RethinkDB Time Query Issue - rethinkdb

I'm trying to run what seems like it should be a pretty basic query from the Data Explorer:
r.db("test").table("test_table").group(r.row('date').dayOfWeek())
where date is a TIME obj
I'm getting the following error:
e: Error in time logic: Year is out of valid range: 1400..10000 in:
r.db("test").table("test_table").group(r.row("date").dayOfWeek())
Any date/time function I try and use on the "date" field gives me the same error.
Here is an example of objects I have stored in the table:
{"iat":{"$reql_type$":"TIME","epoch_time":1467895446.724,"timezone":"-06:00"},"id":"0212197a-4891-4475-a30d-ebebc34ba0e4","minutes":152.78329467773438,"date":{"$reql_type$":"TIME","epoch_time":1467784800,"timezone":"-06:00"}}

One of your documents has a year that is not supported by dayOfWeek. The RethinkDB documentation has this to say:
Most date operations are only defined on years in the range [1400, 10000] (but note that times in the year 10000 cannot be printed as ISO 8601 dates).
You can probably find the offending documents using a query like this:
var limit = r.ISO8601("1400-01-01T00:00Z")
r.table('test_table').filter(r.row('iat').lt(limit).or(r.row('date').lt(limit))

Related

How to use WHERE statement in ni-fi QueryRecord processor?

So I have this dummy csv file:
year, value
2001,А
2001,B
2002,A
2021,B
2022,A
2022,B
I've ingested it using GetFile processor and now I am trying to create few files out of this one
according to a value of "year" column.
So I am using QueryRecord processor and I've created a couple of attributes in this processor such as:
year_2001: select * from flowfile where year = 2001 (also I've tried year = '2001')
year_2022: select * from flowfile where year = 2022
But when I start this processor I am getting some huge error I don't understand. It is too huge to copy here but basically it says that my SQL statement ain't valid. When I remove "where" clause it works fine, so apparently it is the "where" clause that I don't seem to get right.
Thank you beforehand.
UPD. I've found this article and it seems like I do exactly same as example shows.
Ok, I have figure this out. Apparently naming my column "year" wasn't such a good idea. Seems like it conflicted with year function or something. So I just enclosed year in quotes and it worked.
So the correct sql statement will be
select * from flowfile where "year" = '2001'

Laravel 8 and SQL Server: problem with timestamp

Hello everyone and happy new year,
I'm converting my project to use SQL Server instead of MySQL and I'm struggling with the problem of managing timestamps.
In the project, I have this code:
Customers::whereBetween('created_at', [Carbon::now()->subDays('7'), Carbon::now()])->count();
which gives me back the number of new customers registered in the last 7 days.
Using MySQL no problem whatsoever while with SQL Server I get this error:
Converting an nvarchar data type to datetime resulted in a value
outside of the allowable range.
despite in my model, I have set
public function getDateFormat()
{
return 'Y-m-d H: i: s.v';
}
to get the values in milliseconds.
What did I forget to set up?
The error tells you that a conversion failed. Possible reasons:
The date does not exist
If you get February 30th as the input, it will fail.
Input not complying to the format in use
To detect whether this is the problem, you will need to find out what the generated SQL is and find out which value caused this problem. After carefully studying the conversion you should be able to determine what the problem and solution is.

Can't get WORKDAY function to work with a COUNTIF

Trying to work on a system at work that will tell how many error codes were registered by a particular machine on the previous workday. This spreadsheet will need to be able to select only the errors generated on the previous date as this will become a rolling list of data generated across a wide time span. Currently working with the formula
=TODAY(),-1,B2:B17)
where the last array is some shutdown days I've put in to generate a global variable "Yesterday" and trying to use the formula
=COUNTIF(Table1[DateOnly],"="&Yesterday)
to gather the number of records that occurred yesterday.
Can anyone tell me where I'm going wrong?
Found that the issue was when I tried to convert the timestamp in mm/dd/yy hh:mm:ss format to mm/dd/yy and didn't realize that the other information was still hiding in there and confusing the formula. One of my coworkers recommended the use of a ROUNDDOWN function in the use of =ROUNDDOWN(argument,0) to get rid of the time information and just leave me with date.

Elasticsearch scripting - convert unix timestamp to "YYYYMM"

I am using Elasticsearch 2.4 and I have a Groovy script. I have a field in my document say doc['created_unix_timestamp'] which is type integer and it holds Unix timestamp. In a search query's script, I am trying to get YYYYMM from that value.
For example, if doc['created_unix_timestamp'] is 1522703848, then in the scripting during a calculation, I want to convert it to as 201804 where first 4 digits are Year and last two are month (with padded 0, if required)
I tried:
Integer.parseInt(new SimpleDateFormat('YYYYMM').format(new Date(doc['created_unix_timestamp'])))
But it throws "compilation error" "TransportError(400, 'search_phase_execution_exception', 'failed to compile groovy script')" . Any idea how to get it work or what is the correct syntax?
A couple recommendations.
Reindex and make created_unix_timestamp a true date in elasticsearch. This will make all kinds of new querying possible (date range for example). This would be ideal.
If you can't reindex, then pull it back as an int from ES and then convert it to whatever you want client side, I wouldn't recommend pushing that work to the ES cluster.
As per the suggestion of Szymon Stepniak in above comment, I solved this issue by
(new Date(1522705958L*1000).format('yyyyMM')).toInteger()
Thanks and credit goes to Szymon Stepniak

ORA-01861 literal does not match format error when running within larger query

I'm a newbie using Oracle SQL Developer, and running into some issues. When I run the following smaller sample query by itself, it runs fine:
SELECT ((SYSDATE - TO_DATE(table1.a_certain_date_field, 'DD-MON-RR')) / 365.0)
FROM &a_table
WHERE rownum < 5 AND
((SYSDATE - TO_DATE(table1.a_certain_date_field, 'DD-MON-RR')) > 365.0);
But once I embed this into a larger query, I get an ORA-01861 error: literal does not match format string. For example, when I include it with other WHERE conditions, such as
...AND NOT (adr.state = 'WA')
AND
((SYSDATE - TO_DATE(table1.a_certain_date_field, 'DD-MON-RR')) > 365.0)...[more conditions]
What are some reasons why this would occur? My guess is that the table field changed the way that dates were inputted (ie. from DD-MM-YYYY to DD-MON-RR) at some point and caused this error to be thrown, but wouldn't take likewise throw a similar error in the smaller sample code?
This is always (in my experience) a data issue. you can try to narrow it down by looking at various subsets of the data to find out which row/rows are causing it.

Resources