HiveQL - How to use escaped keywords in a WHERE clause? - hiveql

I am trying to query a table by selecting only those cases that meet a certain condition. It is a query called from Beeline, within a R script.
The problem is the field that must meet this condition has a reserved word as a column name: 'table'.
Whenever I run this in an AWS-EMR cluster:
SELECT ... FROM ... WHERE `table` = 'something' AND year = 2018
I get the following error:
bash: table: command not found
Connecting to jdbc:hive2://localhost:10000
Connected to: Apache Hive (version 2.3.2-amzn-0)
Driver: Hive JDBC (version 2.3.2-amzn-0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
. . . . . . . . . . . . . . . . Error: Error while compiling statement: FAILED: ParseException line 1:242 cannot recognize input near '=' ''something'' 'and' in expression specification (state=42000,code=40000)
Closing: 0: jdbc:hive2://localhost:10000
ExitValue: 1
Both blocks marked in bold style should be fixed. Notice that the keyword 'table' is already escaped with backticks.
I have searched the web, but still cannot find a proper solution. Any help would be appreciated.

As #SamsonScharfrichter pointed out in the comments:
Short-term workaround: try escaping back-ticks i.e. \`table\` or maybe \\`table\\`
This worked for my problem.

Related

Multi line command (to export .csv) not working in Apache Drill (web interface)

I am trying to use Apache Drill to export a .csv file. This other question indicated that this is achieved by:
use dfs.tmp;
alter session set `store.format`='csv';
create table dfs.tmp.my_output as select * from cp.`employee.json`;
I tried running this block (of three commands) simultaneously in the Apache Drill web interface but got the error bellow. It somehow is not recognizing the ; or not taking multiple commands.
I also tried running each line separately, without the ; but the changes of the two commands did not persist (and the export command (3rd command) deafauted back to exporting a parquet file (the set default)).
How can I run this in Drill?
Query Failed: An Error Occurred
org.apache.drill.common.exceptions.UserRemoteException: PARSE ERROR: Encountered ";" at line 1, column 12. Was expecting one of: <EOF> "." ... "[" ... SQL Query use dfs.tmp; ^ alter session set `store.format`='csv'; create table dfs.tmp.`elos_cnis` as select * from dfs.tmp.`/bases_parquet/elos_cnis` [Error Id: 00493fbe-924e-43e9-a684-f7d1abfed04e on sbsb35.ipea.gov.br:31010] (org.apache.calcite.sql.parser.SqlParseException) Encountered ";" at line 1, column 12. Was expecting one of: <EOF> "." ... "[" ... org.apache.drill.exec.planner.sql.parser.impl.DrillParserImpl.convertException():391 org.apache.drill.exec.planner.sql.parser.impl.DrillParserImpl.normalizeException():121 org.apache.calcite.sql.parser.SqlParser.parseStmt():149 org.apache.drill.exec.planner.sql.SqlConverter.parse():157 org.apache.drill.exec.planner.sql.DrillSqlWorker.getQueryPlan():104 org.apache.drill.exec.planner.sql.DrillSqlWorker.getPlan():79 org.apache.drill.exec.work.foreman.Foreman.runSQL():1017 org.apache.drill.exec.work.foreman.Foreman.run():289 java.util.concurrent.ThreadPoolExecutor.runWorker():1142 java.util.concurrent.ThreadPoolExecutor$Worker.run():617 java.lang.Thread.run():748 Caused By (org.apache.drill.exec.planner.sql.parser.impl.ParseException) Encountered ";" at line 1, column 12. Was expecting one of: <EOF> "." ... "[" ... org.apache.drill.exec.planner.sql.parser.impl.DrillParserImpl.generateParseException():17963 org.apache.drill.exec.planner.sql.parser.impl.DrillParserImpl.jj_consume_token():17792 org.apache.drill.exec.planner.sql.parser.impl.DrillParserImpl.SqlStmtEof():861 org.apache.drill.exec.planner.sql.parser.impl.DrillParserImpl.parseSqlStmtEof():180 org.apache.drill.exec.planner.sql.parser.impl.DrillParserWithCompoundIdConverter.parseSqlStmtEof():59 org.apache.calcite.sql.parser.SqlParser.parseStmt():142 org.apache.drill.exec.planner.sql.SqlConverter.parse():157 org.apache.drill.exec.planner.sql.DrillSqlWorker.getQueryPlan():104 org.apache.drill.exec.planner.sql.DrillSqlWorker.getPlan():79 org.apache.drill.exec.work.foreman.Foreman.runSQL():1017 org.apache.drill.exec.work.foreman.Foreman.run():289 java.util.concurrent.ThreadPoolExecutor.runWorker():1142 java.util.concurrent.ThreadPoolExecutor$Worker.run():617 java.lang.Thread.run():748
Drill Web-UI does not support submitting multiple queries within the same query page. Please try using SqlLine or submit in Web-UI one-by-one
alter system set `store.format`='csv';
query to set store.format at the system level, since Web-UI does not store session by default and after that submit the following query
create table dfs.tmp.my_output as select * from cp.`employee.json`;

How to resolve a "Metadata error: chr must be valid" error on Linux?

I am relatively new to the world of coding, so I am having trouble resolving an issue when running TranslocWrapper.pl tutorial_metadata.txt preprocess/ results/ --threads 2. I am trying to run the HTGTS Pipeline according to this GitHub project. This is the full error:
. Library Genome Chr Start End Strand
1 RAG1A_SRep2 hg19 chr11 36594878 36595030 -
Metadata error: chr must be valid at /home/micah/transloc_pipeline/bin/TranslocWrapper.pl line 285.
main::check_validity_of_metadata('HASH(0x2903ac8)') called at /home/micah/transloc_pipeline/bin/TranslocWrapper.pl line 248
main::read_in_meta_file() called at /home/micah/transloc_pipeline/bin/TranslocWrapper.pl line 90
I have already double-checked the successful installation of the Software Dependencies, so everything should be all good, but I am having trouble interpreting the "Metadata error: chr must be valid at ..." line. If it helps, these are the specific lines that are being called in the error:
TranslocWrapper.pl line 285:
croak "Metadata error: chr must be valid" unless grep { $_ eq $expt->{chr} } #chrlist;
TranslocWrapper.pl line 248:
check_validity_of_metadata($expt);
TranslocWrapper.pl line 90:
read_in_meta_file;
Thanks in advance for the help!
So the error is saying that one of the sequence characters in the metadata file is not present in the sequence's assembly file.
Given that this is the provided example you should assume that the data is correct and your invocation is faulty.
Have you done the TranslocPreprocess.pl preprocessing steps?
If you have try looking at the first line of the metadata file, identify the assembly entry. Ensure that the assembly file exists and that it contains the required sequence.
One common problem with this kind of code is the case of the filenames. The examples are designed to be run in Linux where filename case matters. Windows likes to pretend that case doesn't matter, this can cause problems. If you are running this code from Microsoft Windows or extracted any of the archives from within Windows this is a likely cause of the error.

q - cannot load log4q

I would like to use log4q. I downloaded the log4q.q file to my %QHOME% directory. When I try to load the script
C:\Dev\q\w32\q.exe -p 5000
q) \l log4q.q
I get
'
[0] (<load>)
)
When I try the same in qpad after connecting to localhost server I get
'.log4.q
(attempt to use variable .log4.q without defining/assigning first (or user-defined signal))
which I find strange because I can switch to non-existing namespaces in the console without any issues.
Thanks for the help!
It looks like a typo in the first line stemming from a recent change of namespace from .l to .log4q
I think the first line should be:
\d .log4q
not
\d .log4.q

Is DB2 CLPPLUS editor able to do xquery

I am new to the CLPPlus editor and I'm trying a simple query that works if I execute it from a file like this
db2 -td% -svf C:\query.sql
and the query.sql file contains:
SELECT tx.ID,XMLQUERY('for $e in $d/Client/Address return data($e)' passing tx.contactinfo as "d") FROM clients tx %
If I just place the query as it is in the CLP or CLPPLUS editor as it is I get errors.
Error FROM CLP: SQL0104N An unexpected token "for $e in $d/Client/Ad"
was found following "LECT tx.ID,XMLQUERY(". Expected tokens may
include: "
Error from CLPPLUS: SQL16002N An XQuery expression has an unexpected
token "in" following "for ". Expected tokens may include: "is". Error
QName=err:XPST0003.

XQuery expression has an unexpected token "/"

So I'm working with DB2 from command line. Before you ask, yes, it is running with admin rights and I can connect to the database and db2 is running.
Here is my input in the cmd:
db2 xquery declare default element namespace "http://tpox-benchmark.com/security"; for $s in db2-fn:xmlcolumn("SECURITY.SDOC")/Security where $s/Symbol= "BCIIPRC" return $s
And this is the error that I get:
SQL16002N An XQuery expression has unexpected token "/" following
"pace http:". Expected tokens may include: ":". Error
QName=err:XPST0003. SQLSTATE=10505
And your question is?
Your shell may be stripping away those double quotes. Try enclosing the entire xquery statement in single quotes:
db2 'xquery declare ... return $s'
I replaced the " with ' and it works now. Thanks #mustaccio for the suggestion.
db2 xquery declare default element namespace "http://tpox-benchmark.com/security"; for $s in db2-fn:xmlcolumn("SECURITY.SDOC")/Security where $s/Symbol= "BCIIPRC" return $s