Hive SQL Select is not working with multiple AND criteria, showing error: The operator 'AND' accepts at least 2 argument - hive

I am trying to run a very simple query that just select all the rows based upon some multiple criteria and all are inclusive i.e. I am using AND in select HiveQL statement. The table is an external table in Hive and the storage handler is phoenix, so I checked in phoenix also about that query and it is working fine, but in Hive, it is showing some java IO exception error which I am not able to get where I am wrong. The query I am using is:
SELECT * FROM msme_api.msme_jk WHERE gender='Male' AND socialcategory='General';
The complete error message is:
Error: java.io.IOException: org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException: The operator 'AND' accepts at least 2 argument. (state=,code=0)
I am trying for external and for internal Hive tables, In both, the issues are still the same but when I give order by, OR statement then it's surprising that it works.
SELECT * FROM msme_api.msme_jk WHERE gender='Male' AND socialcategory='General' order by aid;
SELECT * FROM msme_api.msme_jk WHERE gender='Male' OR socialcategory='General';
Both works fine but with AND, I am getting the error.
I still confused about how hive is taking and processing the above queries and why I am not able to execute simple select statement. Any help will be appreciated.

Related

Argument type mismatch in hive action via OOZIE

I am running hive action in oozie, where hive.sql script has the below mentioned hive query.
Agenda:
Goal is to insert the outcome of this query into hive integrated hbase table, where main goal is to retrieve latest timestamp via transaction_dt column.
However when I run the same query via hive action in OOZIE, it fails with
error message:
org.apache.hadoop.hive.ql.parse.SemanticException: Line 0:-1 Argument
type mismatch 'rows': The 1st argument of EQUAL is expected to a
primitive type, but list is found
Seems like UDF defined variable is not expected here, however primitive type is expected.
When I run this query manually on hive shell, it works perfectly.
insert overwrite table hive_lookup_hbase
Select lookup.card_id, lookup.UCL, lookup.postcode, lookup.transaction_dt,lookup.score
from
(
SELECT ct.card_id, row_number() over ( partition by ct.card_id order by ct.transaction_dt desc ) rows,
ct.postcode , ct.member_id, ct.transaction_dt, ms.score, c_u_look.UCL
FROM hive_cardtrans_hbase ct
join cid_ucl_lookup c_u_look
join member_score ms on c_u_look.card_id=ct.card_id and ms.member_id=ct.member_id
)lookup
where rows=1;
As it works with hive shell, needs to know what changes I can make to make it work with oozie.
I'm not sure is this responsible for exception but obviously the join without ON condition is bad thing because it is CROSS JOIN. It seems the ON condition for the first join is not where it should be. It should be like this, isn't it?
FROM hive_cardtrans_hbase ct
join cid_ucl_lookup c_u_look on c_u_look.card_id=ct.card_id
join member_score ms on ms.member_id=ct.member_id
not this:
FROM hive_cardtrans_hbase ct
join cid_ucl_lookup c_u_look
join member_score ms on c_u_look.card_id=ct.card_id and ms.member_id=ct.member_id
Issue got fixed by setting the set hive.auto.convert.join=false in hive script.
This basically disables the optimization done by OOZIE, i thought, this option was disabled by default.

SQL Vertica on Tableau: row_number over partition by multiple fields error

I have a query that uses
row_number() over(partition by a,b)
When I run the query in dbvisualizer, it runs fine. When I try to use it as a custom SQL query in Tableau, it throws the error:
Error 3537: Incorrect number of parameters for prepared statement _PLAN000011EBDD67590_42
Any idea what I should do? I need my data partitioned by both a and b but Tableau just isn't happy with it.
It's very probably not the ROW_NUMBER() function that perplexes Tableau.
"Incorrect number of parameters" usually means that you have a different number of parameter markers in a query that contains for example WHERE purchase_date = ?, and you maybe try to pass two values in a filter of your report.
I would check for the query that Tableau wants to send in detail, and look at the filter you are using to find inconsistencies .

How to execute multiple Oracle sql queries from VBscript?

I have a database object called objdb. From this object it seems that I can only execute one sql query at a time. if I insert a semi-colon in the end,it gives me a
ORA-0911 invalid character error.
For example, if I run
objdb.executeSQl("select * from table1; select * from table2")
This gives me a error.
How can I run multiple queries from a single ExecuteSQl method ?

how to debug "sql subquery returns more than 1 row" error

We have a huge SQL script involving tens of tables, subqueries, hundreds of attributes. It works perfectly in the test database but returns sql subquery returns more than 1 row error when running in the production database. The script was working perfectly up until now. The problem is, all I get is a one-line error specified above with no clues whatsoever which exact subquery causes the error which makes it near to impossible to debug. The question is, how am I supposed to know which line of the SQL causes the error? Is there any way to "debug" it line by line like you would do it in a programming language?
I am using TOAD with Oracle 11g.
Add print or DBMS_OUTPUT.PUT_LINE commands to your script to print messages. And/or use exception handlers in the script. Possibly add some variables that count or label which statement you are at, and output that in the exception handler.
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/errors.htm
Once you have found the query that causes the problem, convert it to a similar query with an appropriate group by and having count(*) > 1 so that you can see what data caused the problem. For instance if you have a correlated subquery that looks like:
(select name from names where id=foo.id)
then write a similar query
select id from names group by id having count(*) > 1
to identify the offending data.
If you have multiple subqueries in the query that produces the error, you could temporarily convert the subqueries to use temporary tables and search them all for duplicates.

Synonyms have stopped working in BigQuery

All of a sudden I cannot get synonyms for tables working in BigQuery, so a query like the following works fine:
select id as id, value as value
from pos_dw_api.test
But a query like the following fails:
select a.id as id, a.value as value
from pos_dw_api.test a
The error returned is the following. I have run this from the web console:
Query Failed
Error: Unknown field: a.id
Synonyms were working just fine last week ... The example table I'm using for this select is 387047224813.pos_dw_api.test.
Has the syntax for synonyms changed? Is this a bug?
Table synonyms generally only work when you're doing a JOIN. I don't know of anything that would have caused this to change. I realize that this is kind of strange, and I've filed an internal bug to fix it.