How to insert by select? - hive

There is a CREATE TABLE t1 (a int, b int, x string), and the instruction SELECT 1 a, 2 b, 'hello' x; is valid, so I expected that it is not an error:
INSERT INTO my_db.t1 SELECT 1 a, 2 b, 'hello' x;
-- OR
INSERT INTO my_db.t1 SELECT a, b, x FROM t2;
Why it is an error? ... Or it is a bug?
Error: Error while compiling statement: FAILED: ParseException line 1:40 Failed to recognize predicate ''. Failed rule: 'regularBody' in statement (state=42000,code=40000)
NOTES.
Also tested INSERT OVERWRITE TABLE my_db.t1 PARTITION(x) SELECT ... when used t with partition... but same error.
Seems why does inserting record into hive fails with FailedPredicateException? but in my case it not works also with SELECT FROM.
Hive version seems 1.2... hive --version say
2021-03-26 09:22:44,840 DEBUG [main] util.HiveVersionInfo: version: #org.apache.hive.common.HiveVersionAnnotation(version=1.2.1000.2.6.4.0-91, shortVersion=1.2.1000, revision=87f2bc04724e559819902a574e78b2beeaf9f541, branch=(detached from 87f2bc0), user=jenkins, date=Thu Jan 4 10:47:01 UTC 2018, url=git://ctr-e134-1499953498516-209689-01-000004.hwx.site/grid/0/jenkins/workspace/HDP-parallel-centos7/SOURCES/hive, srcChecksum=73af1d20b2f8a15f36ac132297e70386)
Hive 1.2.1000.2.6.4.0-91
Subversion git://ctr-e134-1499953498516-209689-01-000004.hwx.site/grid/0/jenkins/workspace/HDP-parallel-centos7/SOURCES/hive -r 87f2bc04724e559819902a574e78b2beeaf9f541
Compiled by jenkins on Thu Jan 4 10:47:01 UTC 2018
From source with checksum 73af1d20b2f8a15f36ac132297e70386
2021-03-26 09:22:45,177 DEBUG [Thread-0] util.ShutdownHookManager: ShutdownHookManger complete shutdown.

Related

Write system date and time as string to gdx

I want to store the system date and time as a string to gdx when executing a script, preferably with a custom format.
I tried the following:
parameter
exec_date execution date
exec_time execution time
;
exec_date = '%system.date1%';
exec_time = '%system.time%';
However I get the following error message in the .lst file:
1 parameter
2 exec_date execution date
3 exec_time execution time
4 ;
5
6 exec_date = 'Dec 17, 2020';
**** $119,140,409
**** 119 Number (primary) expected
**** 140 Unknown symbol
**** 409 Unrecognizable item - skip to find a new statement
**** looking for a ';' or a key word to get started again
7 exec_time = '13:24:05';
**** $119,409
**** 119 Number (primary) expected
**** 409 Unrecognizable item - skip to find a new statement
**** looking for a ';' or a key word to get started again
The following snippet gives the same error message:
variable
exec_date execution date
exec_time execution time
;
exec_date = '%system.date1%';
exec_time = '%system.time%';
Finally, the following snippet runs without error:
$set exec_date = '%system.date1%';
$set exec_time = '%system.time%';
However it seems that both exec_date and exec_time are not dumped to gdx:
gams date gdx=date
Moreover, I tried to display exec_date and exec_time:
display
exec_date
exec_time;
However, I get the following error message in the .lst file:
21 display
22 exec_date
**** $140
**** 140 Unknown symbol
23 exec_time;
**** $140
**** 140 Unknown symbol
Is it possible to store the system date and time as a string to gdx?
Moreover, is it possible to format the date string as yyyy-mm-dd?
It can be implemented as set:
set
exec_date /'%system.date%'/
exec_time /'%system.time%'/
;
display
exec_date
exec_time
;
This outputs:
---- 31 SET exec_date
12/17/20
---- 31 SET exec_time
15:32:46
And is saved to gdx using
gams date gdx=date

unable to get get all occurrences of matched regex_substr in single row oracle

I am trying to get specific data from my database column in oracle 11g but my regular expression is returning me only the first occurrence. Any idea how can i get all the occurrences in same row seperated by "|"??
My query:
SELECT regexp_substr(
'"Error:" {user_1#domain.com}<"User_2" {user_2#domain.com};"Error:" {user_3#domain.com}<"User_4" {user_4#domain.com};',
'Error:[^<]+<'
) AS emails
FROM DUAL;
My Output should be:
Error:" {user_1#domain.com}< Error:" {user_3#domain.com}<
Current output is:
Error:" {user_1#domain.com}<
For clear understanding, I am attaching dml of insert statement in my table:
insert into tests(result) values ('</span></td></tr><tr><td><span class="inputlabel">[14].</span>&nbsp&nbsp<span class="label">ORC|Boston Medical Center|||||||||||||
</span></td></tr><tr><td><span class="inputlabel">[15].</span>&nbsp&nbsp<span class="label">OBR|05-123|LOINC-Lcl-11546-9-1|20050415||||||||||LocalCode: Abscess2||||c|||||
</span></td></tr><tr><td class="errorlabel" nowrap>Error: Report Status Code (ReportStatusCode of type ID) value (c) is invalid Vocabulary code.</td></tr><tr><td class="errorlabel" nowrap>Message rejected.</td></tr><tr><td><span class="inputlabel">[17].</span>&nbsp&nbsp<span class="label">PID||||||||RecCtl_ID|FORTES|AVERY||||||||||||||||||
</span></td></tr><tr><td><span class="inputlabel">[18].</span>&nbsp&nbsp<span class="label">NK1|NK Last Name|NK First Name||||||||||
</span></td></tr><tr><td><span class="inputlabel">[19].</span>&nbsp&nbsp<span class="label">ORC|Boston Medical Center|||||||||||||
</span></td></tr><tr><td><span class="inputlabel">[20].</span>&nbsp&nbsp<span class="label">OBR|05-123|LOINC-Lcl-11546-9-1|20050415||||||||||Local 128477000||||Report_Status_Code 12345678_30|||||
</span></td></tr><tr><td><span class="inputlabel">[21].</span>&nbsp&nbsp<span class="label">OBX|LOINC-Lcl-11546-9-4|SMED-Lcl-78181009-4|||||F|200504231010|BMC
</span></td></tr><tr><td class="inputlabel" nowrap>Processing Results: 3 Messages Accepted, <span class="errorlabel">1 Messages Rejected.</span></td></tr><tr><td class="inputlabel" nowrap>End Time: 2011-08-07 18:47:47.312</td></tr></table>
</span></td></tr><tr><td class="errorlabel" nowrap>Error: Report Status Code (ReportStatusCode of type ID) value (c) is invalid Vocabulary code.</td></tr><tr><td class="errorlabel" nowrap>Message rejected.</td></tr><tr><td><span class="inputlabel">[17].</span>&nbsp&nbsp<span class="label">PID||||||||RecCtl_ID|FORTES|AVERY||||||||||||||||||
')
Table Creation:
create table TESTS
(
result CLOB
)
Now i want all the error messages from the above HTML i.e. output should be like this:
Error: Report Status Code (ReportStatusCode of type ID) value (c) is invalid Vocabulary code Error: Report Status Code (ReportStatusCode of type ID) value (c) is invalid Vocabulary code
Right now i am getting only 1 error message.
I'm not particularly good at it, but - see if it helps.
sample data from line #1 - 4
TEMP CTE splits the string into rows
final select (line #10 onward) aggregates results that contain "Error"
SQL> select * From v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for 64-bit Windows: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
SQL> with test (col) as
2 (select '"Error:" {user_1#domain.com}<"User_2" {user_2#domain.com};"Error:" {user_3#domain.com}<"User_4" {user_4#domain.com};'
3 from dual
4 ),
5 temp as
6 (select regexp_substr(col, '[^<;]+', 1, level) val
7 from test
8 connect by level <= regexp_count(col, '<') + 1
9 )
10 select listagg(val, '< ') within group (order by val) result
11 from temp
12 where instr(val, 'Error') > 0;
RESULT
--------------------------------------------------------------------------------
"Error:" {user_1#domain.com}< "Error:" {user_3#domain.com}
SQL>
With sample data you posted:
SQL> set pagesize 100
SQL> set long 10000
SQL>
SQL> with
2 temp as
3 (select regexp_substr(result, '[^<;]+', 1, level) val
4 from tests
5 connect by level <= regexp_count(result, '<') + 1
6 )
7 select replace(val, 'td class="errorlabel" nowrap>', '') result
8 from temp
9 where instr(val, 'Error') > 0;
RESULT
--------------------------------------------------------------------------------
Error: Report Status Code (ReportStatusCode of type ID) value (c) is invalid Voc
abulary code.
Error: Report Status Code (ReportStatusCode of type ID) value (c) is invalid Voc
abulary code.
SQL>
This answers the original version of the question.
If you want multiple substrings, then the right strategy is regexp_replace(). I think this is doing what you specify:
SELECT regexp_replace(
'"Error:" {user_1#domain.com}<"User_2" {user_2#domain.com};"Error:" {user_3#domain.com}<"User_4" {user_4#domain.com};',
'"(Error:[^<]+<)[^;]+;',
'\1'
) AS emails
FROM DUAL;
Here is a db<>fiddle.

`FOR UPDATE` breaks batch execution in HANA

HANA 102.05 fails to execute the following code:
CREATE TABLE ATABLE( f INT );
CREATE PROCEDURE TestProc()
AS
BEGIN
SELECT f FROM ATABLE
FOR UPDATE; -- Without FOR UPDATE it works
END;
SELECT 'Hello' FROM DUMMY;
complaining that:
SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "SELECT": line 8 col 2 (at pos 124)
which points outside the proceudure, at SELECT 'Hello'. The procedure itself compiles without error. The entire script completes successfully if I remove the FOR UPDATE directive. What is wrong with the original?
Update
When I execute the same query from hdbsql.exe I get:
0 rows affected (overall time 26,076 msec; server time 6518 usec)
* 257: sql syntax error: line 5 col 9 (at pos 71) SQLSTATE: HY000
* 257: sql syntax error: incorrect syntax near "END": line 2 col 1 (at pos 32) SQLSTATE: HY000
'Hello'
"Hello"
1 row selected (overall time 4644 usec; server time 143 usec)

00917. 00000 - "missing comma" in Oracle

INSERT INTO PatientTbl(sysID,id,name,dob,phone,hospVisits(hostChg,vDate,refDoc,docChg))
VALUES('P002','491221019V','Dulani Perera','3-FEB-49',
phone_arr_ty(0112233211),hospVisitsNt_ty_tbl(hospVisits_ty(75.00,'25-MAY-06',
(SELECT REF(d) FROM DoctorTbl d WHERE d.regNo=2342111322),550.00)),
hospVisitsNt_ty_tbl(hospVisits_ty(90.00,'29-MAY-06',(SELECT REF(d) FROM DoctorTbl d
WHERE d.regNo=2344114344),300.00)
)
);/
When I'm trying to run above query it will generate following error.
Error starting at line : 65 in command -
INSERT INTO PatientTbl(sysID,id,name,dob,phone,hospVisits(hostChg,vDate,refDoc,docChg)) VALUES('P002','491221019V','Dulani Perera','3-FEB-49', phone_arr_ty(0112233211),
hospVisitsNt_ty_tbl(hospVisits_ty(75.00,'25-MAY-06',(SELECT REF(d) FROM DoctorTbl d WHERE d.regNo=2342111322),550.00)),
hospVisitsNt_ty_tbl(hospVisits_ty(90.00,'29-MAY-06',(SELECT REF(d) FROM DoctorTbl d WHERE d.regNo=2344114344),300.00))
)
Error at Command Line : 65 Column : 58
Error report -
SQL Error: ORA-00917: missing comma
00917. 00000 - "missing comma"
*Cause:
*Action:
I think there shouldn't be issue in commas. How to solve this ?
The error is being raised at the opening parenthesis of the nest table type:
INSERT INTO PatientTbl(sysID,id,name,dob,phone,hospVisits(hostChg, ...
^
Your PatientTbl has a nested table column. You seem to be trying to specify the details of that table's object type inside the insert statement, which isn't correct.
Assuming that nest table column is called hospVisits you would just do:
INSERT INTO PatientTbl(sysID,id,name,dob,phone,hospVisits)
VALUES('P002','491221019V','Dulani Perera','3-FEB-49',
phone_arr_ty(0112233211),hospVisitsNt_ty_tbl(hospVisits_ty(75.00,'25-MAY-06',
(SELECT REF(d) FROM DoctorTbl d WHERE d.regNo=2342111322),550.00)),
hospVisitsNt_ty_tbl(hospVisits_ty(90.00,'29-MAY-06',(SELECT REF(d) FROM DoctorTbl d
WHERE d.regNo=2344114344),300.00)
)
);
But your nested table construction is wrong too; you are trying to use two separate hospVisitsNt_ty_tbl with a single hospVisits_ty in each, rather than a single hospVisitsNt_ty_tbl with multiple hospVisits_ty:
INSERT INTO PatientTbl(sysID,id,name,dob,phone,hospVisits)
VALUES('P002','491221019V','Dulani Perera',date '1949-02-03',
phone_arr_ty(0112233211),
hospVisitsNt_ty_tbl(
hospVisits_ty(75.00, date '2006-05-25',
(SELECT REF(d) FROM DoctorTbl d WHERE d.regNo=2342111322),550.00),
hospVisits_ty(90.00,date '2006-05-29',
(SELECT REF(d) FROM DoctorTbl d WHERE d.regNo=2344114344),300.00)
)
);
I've also switched to using ANSI date literals, on the assumption (and hope) that those columns are actually dates not strings. You were relying on NLS parameters, which you don't usually have control over, and implicit date conversion is not a good idea as it can fail when other people run your code.
You will get unexpected results even in your own environment because you're using 2-digit years; the string '3-FEB-49' would be implicit converted to 2049, not 1949 (which is looks like you would expect):
alter session set nls_date_format = 'DD-MON-RR';
select to_char(to_date('3-FEB-49'), 'YYYY-MM-DD') from dual;
TO_CHAR(TO
----------
2049-02-03
And that's if your defaut model has RR, RRRR or YY; if it happens to have YYYY then you'd get 0049-02-03.
Object build and insertion tested with some made-up data types, as you haven't provided yours:
create type doctor_ty as object (regNo number)
/
create table DoctorTbl of doctor_ty
/
create type hospVisits_ty as object (hostChg number,vDate date,
refDoc ref doctor_ty,docChg number)
/
show errors
create type hospVisitsNt_ty_tbl as table of hospVisits_ty
/
create type phone_arr_ty as object (num number)
/
create table PatientTbl(sysID varchar2(4),id varchar2(12),name varchar2(30),dob date,
phone phone_arr_ty,hospVisits hospVisitsNt_ty_tbl)
nested table hospVisits store as hospVisitsNt return as locator;
/
INSERT INTO PatientTbl(sysID,id,name,dob,phone,hospVisits)
VALUES('P002','491221019V','Dulani Perera',date '1949-02-03',
phone_arr_ty(0112233211),
hospVisitsNt_ty_tbl(
hospVisits_ty(75.00, date '2006-05-25',
(SELECT REF(d) FROM DoctorTbl d WHERE d.regNo=2342111322),550.00),
hospVisits_ty(90.00,date '2006-05-29',
(SELECT REF(d) FROM DoctorTbl d WHERE d.regNo=2344114344),300.00)
)
);
1 row inserted.

Error: ORA-06550 in Oracle 10g

Here i have created a package,with package specification and package body,which contains a procedure which insert a row in table,package creation is successful but execution of that package is giving me error
ORA-06550
Package specification:
create or replace package pkgEmp --package specification created..
as
procedure insertEmp(eno number,name varchar2,job varchar2,mgr varchar2,salary number);
end pkgEmp;
package body:
create or replace package body pkgEmp
as
procedure insertEmp(eno number,name varchar2,job varchar2,mgr varchar2,salary number)
is
begin
insert into emp values(eno,name,job,mgr,salary);
end insertEmp;
end pkgEmp;
Exeuting procedure insertEmp:
begin
pkgEmp.insertEmp(&eno,&name,&job,&mgr,&salary); --i m trying to get data in run time.
End;
and output:
ORA-06550: line 2, column 18:
PLS-00103: Encountered the symbol "&" when expecting one of the following:
( ) - + case mod new not null others
table avg count current exists max min prior sql stddev sum
variance execute multiset the both leading trailing forall
merge year month DAY_ hour minute second timezone_hour
timezone_minute timezone_region timezone_abbr time timestamp
interval date
1. begin
2. pkgEmp.insertEmp(&eno,&name,&job,&mgr,&salary);
3. End;
Why I am not able to get data from User,I m using SQL*Plus
I think you need to put parameters in 'single quotes' like '&name' where the datatype is non-integer.
Thanks,
Aditya