DATA_READ ERROR in hive+oracle join query in apache drill - apache-drill

I tried a join query in hive & oracle:
select x.net_profit, y.city from hive.testdb.`catalog_sales` x inner join oracle.USER.`customer_address` y on y.address_id = x.bill_add_id
Data types for these fields in Drill (I checked using describe table) :
address_id : Decimal
city : CHARACTER VARYING
bill_addr_id : Double
net_profit : Double
Above query worked & I got desired output.
I tried :
select y.city, sum(x.net_profit) from hive.testdb.`catalog_sales` x inner join oracle.USER.`customer_address` y on y.address_id = x.bill_addr_id group by y.city
I got the following Exception:
Error: DATA_READ ERROR: The JDBC storage plugin failed while trying setup the SQL query.
sql SELECT "CA_CITY", CAST("ADDRESS_ID" AS DOUBLE) "$f13"
FROM "USER"."CUSTOMER_ADDRESS"
plugin oracle
Fragment 0:0
[Error Id: 7a2106da-1326-4de1-81e4-338a37acd7f9 on 192.168.145.151:31010] (state=,code=0)
Since joined columns(address_id,bill_addr_id) has different datatypes ie Decimal & Double but these are similar. So, I think this should be handled.
Is casting from Decimal to Double not possible? or is this a bug?

Related

MySql Query acts differently on my local version (8.0.21) and my staging (5.7.12)

I have an issue running a query on MySql using a Goapplication.
My local version works fine using mysql 8.0.21 but the same query on my staging version 5.7.12 on aurora fails
SELECT COUNT(*) AS cnt
FROM (
SELECT ? AS item_id, ? AS ar
)
AS A
JOIN item ON A.item_id = item.id
AND A.ar + item.existing_qty > item.qty;
Running this code in data grip with replacements works fine on both local and staging
Running this code but replacing the question marks with ints works fine
The error I get is:
Error 1054: Unknown column 'A.ar' in 'field list
I am thinking there is some driver / version issue
Does it work if you phrase the query like this?
select count(*)
from item
where item = ? and existing_qty + ? < qty
This is the same logic as your original query, and the parameters are passed in the same order.

Select Query throwing Invalid number error

Hello first time using Oracle SQL Developer and I'm trying to do a select join on two tables and I get the error "ORA-01722: invalid number". What is causing this error?
All of the Google results point to creates/inserts that are invalid.
Here is my query, both CUSTNO and ARCUSTO_ID are of type NUMBER(15,0)
SELECT
ARCUSTO.COMPANY, SHIP_TO.ADDR1
FROM
ARCUSTO
INNER JOIN
SHIP_TO ON ARCUSTO.CUSTNO = SHIP_TO.ARCUSTO_ID;

RODBC sqlQuery: name with special character #

I am using RODBC to merge two tables in ACCESS. Here are my codes:
qry <- "SELECT * FROM
table1 LEFT OUTER JOIN table2
ON table1.Ref# = table2.Ref# "
result <- sqlQuery(connection, qry)
str(result)
Which returns the following error message:
"42000 -3100 [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression
I believe it's because I didn't use "table1.Ref# = table2.Ref#" correctly. With the special character, how can I modify this query? Thank you very much in advance.
Try wrapping the field names with special characters inside square brackets.
SELECT
*
FROM
table1
LEFT JOIN
table2
ON
[table1].[Ref#] = [table2].[Ref#]
Also Access does not support OUTER Join, so simply try LEFT Join.

SQL query access pivot - error message 'field that has an invalid data type'

I'm running an SQL Query on MS Access.
the query looks like this:
TRANSFORM MIN(X_VALUE*MULTIPLE & ' ' & Y_VALUE)
SELECT A.ID
FROM ((MY_TABLE_A A
INNER JOIN MY_TABLE_B B ON B.ID = A.ID)
INNER JOIN MY_TABLE_C C ON C.FOO1_ID = A.FOO1_ID)
LEFT JOIN MY_TABLE_D D ON A.FOO2_ID = D.FOO2_ID
WHERE A.NUM ='FOO'
AND A.FOO_ID<>0
AND FOO3=1
GROUP BY A.ID PIVOT X_NAME IN('BLAH1', 'BLAH2')
when running this against local MDB file, it works.
when running this against Linked MDB (tables are linked to remote Oracle DB), I'm getting
ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] The Microsoft
Access database engine could not execute the SQL statement because it
contains a field that has an invalid data type.
I've googled it, and couldn't find anything useful.
Any idea what can I do?
thanks.
The only statement in the query that even vaguely seems it would cause data type issues is the mixed types in the transform statement. Perhaps the following would work:
TRANSFORM MIN(CSTR(X_VALUE*MULTIPLE) & ' ' & CSTR(Y_VALUE))

MySQL Syntax error message "Operand should contain 1 column(s)"

I tried running the following statement:
INSERT INTO VOUCHER (VOUCHER_NUMBER, BOOK_ID, DENOMINATION)
SELECT (a.number, b.ID, b.DENOMINATION)
FROM temp_cheques a, BOOK b
WHERE a.number BETWEEN b.START_NUMBER AND b.START_NUMBER+b.UNITS-1;
which, as I understand it, should insert into VOUCHER each record from temp_cheques with the ID and DENOMINATION fields corresponding to entries in the BOOK table (temp_cheques comes from a database backup, which I'm trying to recreate in a different format). However, when I run it, I get an error:
Error: Operand should contain 1 column(s)
SQLState: 21000
ErrorCode: 1241
I'm running this in SQuirrel and have not had issues with any other queries. Is there something wrong with the syntax of my query?
EDIT:
The structure of BOOK is:
ID int(11)
START_NUMBER int(11)
UNITS int(11)
DENOMINATION double(5,2)
The structure of temp_cheques is:
ID int(11)
number varchar(20)
Try removing the parenthesis from the SELECT clause. From Microsoft TechNet, the correct syntax for an INSERT statement using a SELECT clause is the following.
INSERT INTO MyTable (PriKey, Description)
SELECT ForeignKey, Description
FROM SomeView
The error you're getting, "The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay.", is actually correct, assuming you have many rows in both BOOK and temp_cheques. You are trying to query all rows from both tables and make a cross-reference, resulting in an m*n size query. SQL Server is trying to warn you of this, before performing a potentially long operation.
Set SQL_BIG_SELECTS = 1 before running this statement, and try again. It should work, but note that this operation may take a long time.
Does B contain the UNITS column?
What is the table structure for temp_cheques and Book?
EDIT: As I said in comments, all the columns should be numeric when doing +/- and when comparing. Does the following simple SELECT work?
SELECT b.START_NUMBER+b.UNITS-1 FROM Books B
I don't have a MySQL instance handy, but my first guess is the WHERE clause:
WHERE a.number BETWEEN b.START_NUMBER AND b.START_NUMBER+b.UNITS-1;
I imagine that the MySQL parser may be interpreting that as:
WHERE number
(BETWEEN start_number AND start_number) + units - 1
Try wrapping everything in parentheses, ie:
WHERE a.number BETWEEN b.START_NUMBER AND (b.START_NUMBER + b.UNITS - 1);
The final version of the query is as follows:
Set SQL_BIG_SELECTS = 1;
INSERT INTO VOUCHER (VOUCHER_NUMBER, BOOK_ID, DENOMINATION)
SELECT a.number, b.ID, b.DENOMINATION
FROM temp_cheques a, BOOK b
WHERE a.number BETWEEN b.START_NUMBER AND (b.START_NUMBER+b.UNITS-1);
The parsing of the BETWEEN statement required parentheses, the SELECT did not, and because of the size of the two tables (215000 records in temp_cheques, 8000 in BOOK) I was breaking a limit on the select size, requiring me to set SQL_BIG_SELECTS = 1.
I ran into the same error when using Spring Repositories.
My repository contained a method like:
List<SomeEntity> findAllBySomeId(List<String> ids);
This is working fine when running integration tests against an in-memory database (h2). However against a stand alone database like MySql is was failing with the same error.
I've solved it by changing the method interface to:
List<someEntity findBySomeIdIn(List<String> ids);
Note: there is no difference between find and findAll. As described here: Spring Data JPA difference between findBy / findAllBy