Getting error in vertica:Function catalog.btrim(int) dose not exist, or permission is denied for catalog.btrim(int) - vertica

I am trying to execute below query in vertica:
select
case when count(*) = 0 then #{aaa} || #{bbb}
else
trim(cast(max(ccc)+1 as intger))
end
as ccc
from apple where aaa = #{aaa}
Query is getting expected results in tera but in Vertica Getting error.
How can I do this?

Check the Vertica docu:
https://www.vertica.com/docs/10.0.x/HTML/Content/Authoring/SQLReferenceManual/Functions/String/BTRIM.htm
BTRIM() removes the blank characters (by default, if not specified as the second parameter) from a passed string. You can't BTRIM() a number.
Why would you want to trim an integer, in trim(cast(max(ccc)+1 as int**e**ger)) ? It makes no sense at all!. Teradata should complain, too.

Related

finding date before 30 days in hive-0.10.0

I have 2 hadoop clusters, One has hive-0.10.0 installed and another has hive-1.1.0 version installed.
I am able to run below query in hive-1.1.0 which gives date before 30 days from present date
select date_sub(from_unixtime(floor(unix_timestamp()/(60*24*24))*60*24*24), 30)
But, the Same query is giving syntax error in hive-0.10.0
ok failed: parseexception line 1:79 mismatched input '' expecting from near ')' in from clause
1.
Way too complected.
This will get you the same result:
select date_sub(from_unixtime(unix_timestamp()),30)
2.
Queries without FROM clause are only supported from hive 0.13
https://issues.apache.org/jira/browse/HIVE-178
Create s table with a single row (similar to Oracle dual) and use it as source

how to grep below sql part from db2 error log

I have a script which extract error messages from db2diag.log. I have to extract the SQL queries which caused the deadlock from the below file.
File contents: log.txt
db2inst1 , WSCOMUSR , MESSAGE : ADM5501I DB2 is performing lock escalation. The affected application
is named "db2jcc_application", and is associated with the workload
name "SYSDEFAULTUSERWORKLOAD" and application ID
"173.10.105.33.59586.13011817552" at member "0". The total number of
locks currently held is "1249935", and the target number of locks to
hold is "624967". The current statement being executed is "delete
from DMEXPLOG where CREATED < ? ". Reason code "1"
db2inst1 , WSCOMUSR , MESSAGE : ADM5501I DB2 is performing lock escalation. The affected application
is named "db2jcc_application", and is associated with the workload
name "SYSDEFAULTUSERWORKLOAD" and application ID
"173.10.105.33.59586.13011817552" at member "0". The total number of
locks currently held is "1249935", and the target number of locks to
hold is "624967". The current statement being executed is "select
* from DMEXPLOG where CREATED < ?". Reason code "1"
Required output: all the sql queries
1. delete
from DMEXPLOG where CREATED < ?
2. select
* from DMEXPLOG where CREATED < ?
like this. I want all sql parts from the file. Any grep or Awk/sed solution to get required output?
Platform: Unix (AIX)
Your current example can be translated with
sed -n '/statement being executed/ s/.*"//p; /Reason code/ s/".*//p' log
awk '{gsub(/^.*The current statement being executed is \"|\". Reason code.*$/,""); print NR". "$0}' log.txt
1. delete from DMEXPLOG where CREATED < ?
2.
3. select * from DMEXPLOG where CREATED < ?
The matching strings could be shorter no doubt and 2. is empty because the data you presented had an empty line between the actual data. Are there empty lines in the actual data?
Maybe, This help you
user#host:/tmp$ sed -n '/select/,/^$/p;/delete/,/^$/p;/insert/,/^$/p;/update/,/^$/p' log.txt | sed -n '/^[0-9]/!H;//x;$x;s/\n\([^A]\)/ \1/gp' | awk -F'"' '{printf("%d.\t %s\n", NR, $4)}'
1. delete from DMEXPLOG where CREATED < ?
2. select * from DMEXPLOG where CREATED < ?

using SQL query on unix [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Select columns into local variable from sql script using shell script
im trying to write a unix script that will retrieve a parameter using sql query and run a script afterwards with this parameter.
for the time being, im just tryin to make it echo the retrieved parameter.
the sql query that works fine on toad (oracle 8) is :
select billcycle from bc_run
where billcycle not in (50,16)
and control_group_ind is null
and billseqno=6043
the above query give a number.
now the script i wrote is:
#!/bin/bash
echo "this script will print the billcycle date"
v_bc=`sqlplus -s /#bscsprod <<EOF
select billcycle from bc_run
where billcycle not in (50,16)
and control_group_ind is null
and billseqno=6043`
echo "billcycle number is $v_bc"
the result when i run the file is
billcycle number is
with no number that follows.
any ideas what's wrong ? maybe the syntax for connecting to the sql server ?
thanks
Assaf.
The duplicate question APC linked to shows a working example, but to clarify you have two problems. The first is non-fatal and is just that you don't have EOF, as Rembunator pointed out (though it's in the wrong place in that answer).
More importantly though you don't have a terminating ; in your query, so SQL*Plus won't execute it - it just exits with no output.
If you typed your original query in as the SQL*Plus command prompt it would leave you at a further prompt waiting for input, and then go back to a normal prompt if you just hit return again, without actually executing the query:
SQL> select billcycle from bc_run
2 where billcycle not in (50,16)
3 and control_group_ind is null
4 and billseqno=6043
5
SQL>
You also probably want at least some formatting of the output. So this should work:
v_bc=`sqlplus -s /#bscsprod <<EOF
set pagesize 0
select billcycle from bc_run
where billcycle not in (50,16)
and control_group_ind is null
and billseqno=6043;
EOF`
I think you should end with EOF as well:
v_bc=`sqlplus -s /#bscsprod <<EOF
select billcycle from bc_run
where billcycle not in (50,16)
and control_group_ind is null
and billseqno=6043
EOF`
Edited: Oops, as corrected by Alex Poole.

Long PL/SQL output in SQLPLUS

Got problem with executing my script under SQLPLUS. Under SQL Developer it works well.
set serveroutput on size 1000000
declare
yyy varchar2(32000):='';
begin
yyy := 'XxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzz';
yyy := yyy || 'XxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzz';
yyy := yyy || 'XxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzzXxxYyyZzz';
dbms_output.put_line(yyy);
end;
/
Under SQLPLUS I get error:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error ORA-06512: at line 1
Any solution how to force running scripts with long output under SQLPLUS? I need output on because I spool results to file.
You are using a Oracle client older than Oracle 10g against an Oracle 10g Database
Please find the quote from ASKTOM below
The problem is NOT during runtime, you are apparently using an old client against a 10.2 or above database. The database code runs fine
It is when the client goes to PICK UP THE STRING from the database that you are hitting the exception.
sqlplus is doing something like this:
a) call procedure/code - it runs and fills a dbms_output buffer, an array in a package.
b) then sqlplus calls dbms_output.GET_LINES to get the buffered output to print. THIS is the call that fails.
For more information Kindly refer
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1011431134399

Hive: writing column headers to local file?

Hive documentation lacking again:
I'd like to write the results of a query to a local file as well as the names of the columns.
Does Hive support this?
Insert overwrite local directory 'tmp/blah.blah' select * from table_name;
Also, separate question: Is StackOverflow the best place to get Hive Help? #Nija, has been very helpful, but I don't to keep bothering them...
Try
set hive.cli.print.header=true;
Yes you can. Put the set hive.cli.print.header=true; in a .hiverc file in your main directory or any of the other hive user properties files.
Vague Warning: be careful, since this has crashed queries of mine in the past (but I can't remember the reason).
Indeed, #nija's answer is correct - at least as far as I know. There isn't any way to write the column names when doing an insert overwrite into [local] directory ... (whether you use local or not).
With regards to the crashes described by #user1735861, there is a known bug in hive 0.7.1 (fixed in 0.8.0) that, after doing set hive.cli.print.header=true;, causes a NullPointerException for any HQL command/query that produces no output. For example:
$ hive -S
hive> use default;
hive> set hive.cli.print.header=true;
hive> use default;
Exception in thread "main" java.lang.NullPointerException
at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:222)
at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:287)
at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:517)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.hadoop.util.RunJar.main(RunJar.java:197)
Whereas this is fine:
$ hive -S
hive> set hive.cli.print.header=true;
hive> select * from dual;
c
c
hive>
Non-HQL commands are fine though (set,dfs !, etc...)
More info here: https://issues.apache.org/jira/browse/HIVE-2334
Hive does support writing to the local directory. You syntax looks right for it as well.
Check out the docs on SELECTS and FILTERS for additional information.
I don't think Hive has a way to write the names of the columns to a file for the query you're running . . . I can't say for sure it doesn't, but I do not know of a way.
I think the only place better than SO for Hive questions would be the mailing list.
I ran into this problem today and was able to get what I needed by doing a UNION ALL between the original query and a new dummy query that creates the header row. I added a sort column on each section and set the header to 0 and the data to a 1 so I could sort by that field and ensure the header row came out on top.
create table new_table as
select
field1,
field2,
field3
from
(
select
0 as sort_col, --header row gets lowest number
'field1_name' as field1,
'field2_name' as field2,
'field3_name' as field3
from
some_small_table --table needs at least 1 row
limit 1 --only need 1 header row
union all
select
1 as sort_col, --original query goes here
field1,
field2,
field3
from
main_table
) a
order by
sort_col --make sure header row is first
It's a little bulky, but at least you can get what you need with a single query.
Hope this helps!
Not a great solution, but here is what I do:
create table test_dat
ROW FORMAT DELIMITED FIELDS TERMINATED BY "\t" STORED AS
INPUTFORMAT "com.hadoop.mapred.DeprecatedLzoTextInputFormat"
OUTPUTFORMAT "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat"
LOCATION '/tmp/test_dat' as select * from YOUR_TABLE;
hive -e 'set hive.cli.print.header=true;select * from YOUR_TABLE limit 0' > /tmp/test_dat/header.txt
cat header.txt 000* > all.dat
Here's my take on it. Note, i'm not very well versed in bash, so improvements suggestions welcome :)
#!/usr/bin/env bash
# works like this:
# ./get_data.sh database.table > data.csv
INPUT=$1
TABLE=${INPUT##*.}
DB=${INPUT%.*}
HEADER=`hive -e "
set hive.cli.print.header=true;
use $DB;
INSERT OVERWRITE LOCAL DIRECTORY '$TABLE'
row format delimited
fields terminated by ','
SELECT * FROM $TABLE;"`
HEADER_WITHOUT_TABLE_NAME=${HEADER//$TABLE./}
echo ${HEADER_WITHOUT_TABLE_NAME//[[:space:]]/,}
cat $TABLE/*

Resources