Hive table taking decimal value as NULL - hive

I am facing strange issue.I tried with tab delimiter both in file and in table definition and comma as well.
But in both cases it reads the decimal values as NULL.But when I define this fields as INT it works fine.
Sample data with comma delimited values:
1,22.334
2,445.322
3,999.233
defined this table as
create table x(ID INT,SAL DECIMAL(3,3)) row format delimited fields terminated by '\t' location '\tmp\data\'
similarly for comma delimited file
create table x(ID INT,SAL DECIMAL(3,3)) row format delimited fields terminated by ',' location '\tmp\data\'
But in both cases it is reading decimal values as NULL?what is the issue

First thing is Decimal datatype doesn't not accept comma in data.
Second problem is you have to increase the decimal(3,3) to minimum decimal(7,3) for the sample data provided.
As decimal (3,3) cannot hold any of 3 values.
As your raw data contains comma in data,
You have to load the into table with all columns as string datatype .
Later use regular expression to remove the comma in data and load into second level hive table with decimal datatype.

Related

Insert commas delimited string into a string column of Athena table

I created an Amazon Athena table based on CSV in S3. I want to input a row of data with one column that includes commas. But it truncates the string from the commas each time.
For example:
insert into table_names (id, key_string)values (1,'{key1=1,key2=3}')
Each time, the column key_string only stores {key1=1.
I tried use double quote "{key1=1,key2=3}", escape char \"{key1=1,key2=3}\".
They don't work.
Any suggestion?

Oracle insert value into a column with power

How can I insert a value into a column with power? Please see the below example:
Can it be done via the UNISTR function?
insert into table values ('2332239 12'); -- I intentionally want to insert the number into a varchar field.
If you mean you want to insert a string that ends with Unicode superscript 12 you can just put Unicode characters in a Unicode string and insert them into a Unicode column:
INSERT INTO table VALUES(N'123¹²')
(Your column will have to be an NVARCHAR)
If your column is a varchar and you can't change it you'll have to encode the data somehow, and decode it very time you want to use it (not ideal)

How to spread the values from a column in Hive?

One field of table is made up of many values seperated by comma,
for example, a record of this field is:
598423,4803510,599121,98181856,1666529,106317962,4061964,7828860,598752,728067,599809,8799578,1666528,3253720,601990,601235
I want to spread the values in every record of this field in Hive.
Which function or method I can use to realize this?
Thanks.
I'm not entirely sure what you mean by "spread".
If you want an output table that has a value in every row like:
598423
4803510
599121
Then you could use explode(split(data,',')
Otherwise, if each input row has exactly 16 numbers and you want each of the numbers to reside in a different column, you have two options:
Define the comma as a delimiter for the input table ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
Split a single column into 16 columns using the split UDF: SELECT split(data,',')[0] as col1, split(data,',')[1] as col2, ...

importing data with commas in numeric fields into redshift

I am importing data into redshift using the SQL COPY statement. The data has comma thousands separators in the numeric fields which the COPY statement rejects.
The COPY statement has a number of options to specify field separators, date and time formats and NULL values. However I do not see anything to specify number formatting.
Do I need to preprocess the data before loading or is there a way to get redshift to parse the numbers corerctly?
Import the columns as TEXT data type in a temporary table
Insert the temporary table to your target table. Have your SELECT statement for the INSERT replace commas with empty strings, and cast the values to the correct numeric type.

sql server data type and return value from select statement

I designed a table with one field of type char(10).
I then I input data to this field but data is less than 10 characters.
Why is it that when I select the data, it returns the data appended with spaces to 10 characters?
char(n) is padding data with spaces ( completed to n)