Athena: Getting a INVALID_CAST_ARGUMENT: Cannot cast 'undefined' to BIGINT when trying to add BIGINT into WHERE clause - amazon-athena

I am trying to run the query below:
SELECT *
FROM sales
WHERE order_id = 34001805542
And am getting a INVALID_CAST_ARGUMENT: Cannot cast 'undefined' to BIGINT when trying to add BIGINT error.
I have tried casting the integer like this to no avail:
WHERE order_id = TRY_CAST(34001805542 AS BIGINT)

Related

AWS Quicksight calculated filed error - division operator not working as expected

I have a dataset with the following fields in Quicksight:
ordered_units, product_category
I am trying to add a calculated field that will give me the percentage of items ordered for each item category. i.e. ordered_units / sum(ordered_units) group by product category
The formula I am using for the calculated field is:
({ordered_units}/sumOver(sum({ordered_units}),[{product_category}])) * 100
But it is not letting me save the field and gives the error:
We encountered an error trying to save your calculated field. Please
try creating it again.
Is there something I am missing or not doing correctly?

Filter a date by current date in PowerQuery / PowerBI

I'm creating a report in PowerBI, and need to filter out some erroneous record from my source. Its a payment table, and some records are with a future date, eg in 2799. I'd like to make a Filter to remove records after today + 1 year. I already had this filter :
= Table.SelectRows(_cobranca, each [Vencimento] >= DATA_LIMITE)
DATA_LIMITE is a parameter, and the code above is already working. I tried to change it to :
= Table.SelectRows(_cobranca, each [Vencimento] >= DATA_LIMITE and [Vencimento] <= DateTime.LocalNow())
But I'm getting this error:
DataFormat.Error: Syntax error in date in query expression '[_].[Vencimento] >= #2020-01-01 00:00:00# and [_].[Vencimento] <= #2020-10-21 10:58:07.4411693'.
It seems that DateTime.LocaNow function is not returning the date in the correct format.
Replace DateTime.LocalNow() with Date.From(DateTime.LocalNow()) as I assume your [Vencimento] column (due date?) is just a date data type not date time

AWS Athena query error when trying to filter by date

I am trying to use Athena to query some data I have stored in an s3 bucket in parquet format. I have field called datetime which is defined as a date data type in my AWS Glue Data Catalog.
When I try running the following query in Athena, I get the error below:
SELECT DISTINCT datetime
FROM "craigslist"."pq_craigslist_rental_data_parquet"
WHERE datetime > '2018-09-14'
ORDER BY datetime DESC;
And the error:
Your query has the following error(s):
SYNTAX_ERROR: line 3:16: '>' cannot be applied to date, varchar(10)
What am I doing wrong here? How can I properly filter this data by date?
the string literal that you provide has to be casted to a date, in order to compare to a date.
where datetime = date('2019-11-27')
its having issue with the string literal used for date filter. Use WHERE datetime > date '2018-09-14'
from_iso8601_date or date should work.
SELECT DISTINCT datetime
FROM "craigslist"."pq_craigslist_rental_data_parquet"
WHERE datetime > from_iso8601_date('2018-09-14')
ORDER BY datetime DESC;
both return a proper date object.
SELECT typeof(from_iso8601_date('2018-09-14'))
Bit late here, but I had the same issue and the only workaround I have found is:
WHERE datetime > (select date '2018-09-14')

DQL Perform a union in query

I know there are several post relatives to this question but I still can't do mine !
I have two tables (studios and models). I want to perform an union for my datatable.
Currently, I have this :
$cnn = $this->Doctrine->getConnection();
$inscr = $cnn->fetchAll("(SELECT s.thedate AS mydate, s.name AS designation, \'Studio\' AS mytype
FROM studios s ORDER BY mydate LIMIT 2)
UNION
(SELECT m.thedate AS mydate, m.nickname AS designation, \'Hotesse\' AS mytype
FROM models m ORDER BY mydate LIMIT 2
)");
return $inscr;
But nothing appears in my datatable and I can't perform any var_dump or other.
I test this in my RDBMS and I get waited results. So, anyone could help ?
I finally found a solution to perform the query and get a result
$sql = "(SELECT s.thedate AS mydate, s.name AS designation, 'Studio' AS mytype
FROM studios s ORDER BY mydate LIMIT 2)
UNION
(SELECT m.thedate AS mydate, m.nickname AS designation, 'Hotesse' AS mytype
FROM models m ORDER BY mydate LIMIT 2
)";
$stmt = $this->em->getConnection()->prepare($sql);
$stmt->execute();
return $stmt->fetchAll();
But, unfortunatly in datatable the result must be an instance of Doctrine\ORM\QueryBuilder and my solution returns an array..
If someone has an idea for my special case, I'm here !

Convert varchar to double fails when I use ADO yet it works in MS Access

I have made a query that ran successfully in the first version of my program, using ADO and C++ to query MS Access 2007 database.
However, the structure of my database had to be modified.
Fields that were once of type double are now varchar.
When I execute the same query on the modified database, it reports data type mismatch, as it should.
EDITED QUERY TO HELP THE POSTER OF THE FIRST SOLUTION:
Here is simplified version of my query:
wchar_t query = L" select ( ads(Field) + Field ) / 2 from MyTable where PrimaryKey = 1;";
Field was of type double, but now is varchar.
I have tried using CDbl like this:
wchar_t query = L" select ( abs( CDbl(Field) ) + CDbl(Field) ) / 2 from MyTable where PrimaryKey = 1;";
It works when I create query in MS Access, but in my program I still get data type mismatch error reported.
I have tried to find alternative on the Internet, and have thought that CAST or CONVERT can sole this, but it seems that they do not work in MS Access.
Is there any solution for this ?
Thank you.
Regards.
Have you tried to convert the value to Double not in the query but after the query has been run?
CAST and CONVERT are not Access SQL functions
I dont use c++ but even with a small subroutine in Access using the ADO object I cannot reproduce the error...
Sub test()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim db As ADODB.Connection
Set db = CurrentProject.Connection
rs.Open "SELECT (Abs(CDbl(Field))+CDbl(Field))/2 AS A FROM MyTable;", db
While rs.EOF = False
Debug.Print rs!A
rs.MoveNext
Wend
End Sub