Cloudera Hue - cannot recognize input near 'WITH' 'SERDEPROPERTIES' '(' in serde properties specification - hive

I'm trying to create this table:
CREATE TABLE
TABLE_DATA
(
A STRING,
B STRING,
C STRING,
D STRING,
E STRING,
F STRING,
G STRING,
H STRING,
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
WITH SERDEPROPERTIES
(
"separatorChar" = ",",
"quoteChar" = "\""
)
STORED AS TEXTFILE LOCATION '...'
TBLPROPERTIES ("skip.header.line.count"="1");
However I'm getting an issue:
Error while compiling statement: FAILED: ParseException line 14:2
cannot recognize input near 'WITH' 'SERDEPROPERTIES' '(' in serde
properties specification
How can I solve it?
Thanks!

ROW FORMAT should be specified once, and remove extra comma after last column
CREATE TABLE TABLE_DATA
(
A STRING,
B STRING,
C STRING,
D STRING,
E STRING,
F STRING,
G STRING,
H STRING
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
WITH SERDEPROPERTIES
(
"separatorChar" = ",",
"quoteChar" = "\""
)
LOCATION '...'
TBLPROPERTIES ("skip.header.line.count"="1");

Related

Remove a special character that exists between 2 characters

I have the following string:
6103951001#136,00#S0#0#99999999#8000010000#10.12.2019#
31.10.2019#"MATZOURAKIS IOANNISMROA118#OSPh"#99470##APE A 54226#K
What I want is to delete the special character HORIZONTAL_TAB(#) which is between " here is the part of the string: "MATZOURAKIS IOANNISMROA118#OSPh"
How can I do?
Thanks
PS. I am using the following to upload the data from a TAB delimited text file
data: data_table type standard table of char255,
wa_data_table like line of data_table.
lv_file = p_file.
cl_gui_frontend_services=>gui_upload(
exporting
filename = lv_file
filetype = 'ASC'
changing
data_tab = data_table
Now I am doing the following in order to catch the problem
loop at data_table into wa_data_table.
find all occurrences of '"' in wa_data_table match count lv_count.
if sy-subrc = 0 and lv_count = 2.
* REPLACE ALL OCCURRENCES OF REGEX
* '(#(?=[^"]*"[^"]*(?:"[^"]*"[^"]*)*$))' IN wa_data_table WITH ' '.
split wa_data_table at '"'
into split_data1 split_data2 split_data3.
replace all occurrences of cl_abap_char_utilities=>horizontal_tab
in split_data2 with ' '.
concatenate split_data1 split_data2 split_data3
into wa_data_table.
endif.
endloop.
I think that we must handle the cl_abap_char_utilities=>horizontal_tab not with the character # but in another way.
You can use following in ABAP to find this character and replace it:
data : lv_test type string VALUE '6103951001#136,00#S0#0#99999999#8000010000#10.12.2019# 31.10.2019#"MATZOURAKIS IOANNISMROA118#OSPh"#99470##APE A 54226#K'.
REPLACE ALL OCCURRENCES OF REGEX '(#(?=[^"]*"[^"]*(?:"[^"]*"[^"]*)*$))' IN lv_test WITH ''.
write lv_test.
This is the correct solution for this problem.
replace all occurrences of regex
'(\t(?=[^"]*"[^"]*(?:"[^"]*"[^"]*)*$))'
in table data_table with ' '.
replace all occurrences of regex '["]' in table data_table with ''.

Why my table not recognize the field delimited?

I'm trying input a text file delimited with ";", but it does not work.
The create tables is OK, but all data is in one column (tp_registro).
tp_registro 1;0000000167;1120112368---------;29012019;172822;4124999762039------;;0000555;0000060;02;00000001416;00000000000;
seq NULL
num_a NULL
dt_chamada NULL
hr_chamada NULL
num_b NULL
pt_interconect NULL
dur_rel_chamada NULL
dur_tar_chamada NULL
tp_servico NULL
vl_liq_chamada NULL
vl_brt_chamada NULL
reserva NULL
CREATE EXTERNAL TABLE IF NOT EXISTS
gd_f_mtr.tbgdt_stg_batimento_cobilling_tim_nconciliado(
tp_registro string,
seq string,
num_a string,
dt_chamada string,
hr_chamada string,
num_b string,
pt_interconect string,
dur_rel_chamada string,
dur_tar_chamada string,
tp_servico string,
vl_liq_chamada string,
vl_brt_chamada string,
reserva string
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '/073'
STORED AS TEXTFILE
LOCATION '/gr/nas/Ex/Op';
Use FIELDS TERMINATED BY '\073' (backslash \, not /)

SQL* Loader Handling formatted dates

I'm developing this solution where I'll receive a spool file and I need to insert it to a table.
I always use SQL* Loader and it fits well. But I never used it with dates. I'm getting this error as I'll show:
Control File
OPTIONS (ERRORS=999999999, ROWS=999999999)
load data
infile 'spool.csv'
append
into table A_CONTROL
fields terminated by ","
TRAILING NULLCOLS
(
AStatus,
ASystem,
ADate,
AUser,
)
spool.csv
foo,bar,2015/01/12 13:22:21,User
But when I run the loader I got this error
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
AStatus FIRST * , CHARACTER
ASystem NEXT * , CHARACTER
ADate NEXT * , CHARACTER
AUser NEXT * , CHARACTER
Record 1: Rejected - Error on table A_CONTROL, column ADate.
ORA-01861: literal does not match format string
Table A_CONTROL:
0 Rows successfully loaded.
1 Row not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Convert the string to date for insertion.
OPTIONS (ERRORS=999999999, ROWS=999999999)
load data
infile 'spool.csv'
append
into table A_CONTROL
fields terminated by ","
TRAILING NULLCOLS
(
AStatus,
ASystem,
ADate "TO_DATE(:ADate,'YYYY/MM/DD HH24:MI:SS')",
AUser,
)

ÿ is not displaying while concatenate with other column in oracle

I have a problem regarding a special character. I have a table test as below:
SQL> desc test
Name Type Nullable Default Comments
-------------- ----------------- -------- ------- --------
DOT DATE Y
LOWVAL_CHAR VARCHAR2(3) Y
I am inserting data in this table using sqlldr. The data file is as below:
1984/01/10ÿ:-1 0 -99999+99999Sourav Bhattacharya
ctl file is as below:
LOAD DATA
CHARACTERSET AL32UTF8
APPEND
PRESERVE BLANKS
INTO TABLE TEST
(dot POSITION(1) CHAR(10) "TO_DATE(:DOT,'YYYY/MM/DD')",
lowval_char POSITION(11) CHAR(1),
highval_char POSITION(12) CHAR(1),
lowval_un_num POSITION(13) INTEGER EXTERNAL(6),
highval_un_num POSITION(19) INTEGER EXTERNAL(6),
lowval_si_num POSITION(25) INTEGER EXTERNAL(6),
highval_si_num POSITION(31) INTEGER EXTERNAL(6),
fn POSITION(37) CHAR(10),
mn POSITION(47) CHAR(5),
ln POSITION(52) CHAR(20)
)
Data got inserted correctly.
Now if I execute the query
select dot,lowval_char from test;
It is giving me correct result but if I concatenate i.e
select dot||lowval_char from test;
ÿ is not displaying, only the dot value is visible.
If I do not use SQL loader and do any insert into it is giving correct result for both the cases.
Settings:
character set is AL32UTF8
nls_language='AMERICAN'
NLS_LENGTH_SEMANTICS='BYTE'

SQL Function to replace space with , and | with space and copy text (SQL Server 2008 R2)

I am just a starter in SQL Scripting and I have a field A containing string values in the following format:
X1|Y1 X2|Y2 X3|Y3 X4|Y4 X5|Y5
I am trying to create a function to replace the space with , and then replace | with a space. After that, put , at the end of the string and paste the chars before the first space comma in the string "X1 Y1" to the end of the text.
So, the resulting text in the field B will be as follows:
X1 Y1,X2 Y2,X3 Y3,X4 Y4,X5 Y5,X1 Y1
Fields A and B are of type: ntext
Note: I tried to use the replace function but got the error message: Argument data type ntext is invalid for argument 1 of replace function
Thanks
In SQL Server 2008R2:
SELECT REPLACE(#mystring,'|',',') + ' ' + REPLACE(LEFT(#mystring,CHARINDEX(' ',#mystring)-1),'|',',')
replacing #mystring with the name of your field.
MySQL:
Select Replace(colName,"|",",")
You cannot use REPLACE with blob fields, you should convert it first to string field
try this:
select replace(replace(cast(a as nvarchar(max)) + ' ' + left(cast(a as nvarchar(max)),
charindex(' ', cast(a as nvarchar(max))) - 1),' ',','),'|',' ')
from aaa