Space in Hive output - hive

I want my Query output whitespace separate. I just want output fields to be separated only by one space. I used the below settings but I get ABC ^A 9000. So, there is ^A in between.
How can I do one space between fields?
INSERT OVERWRITE LOCAL DIRECTORY '/home/stg/hive_training'
ROW FORMAT DELIMITED
FIELDS terminated by''

Just use space. It works.
Demo
hive
insert overwrite local directory '/tmp/test'
row format delimited
fields terminated by ' '
select 1,2,3
;
bash
</tmp/test/000000_0 od -Anone -a
1 sp 2 sp 3 nl

Related

read a csv file with comma as delimiter and escaping quotes in psql

I want to read a csv file which is separated by comma (,) but want to ignore comma within the double quotes (""). I want to store the result into a table.
Example:
abc,00.000.00.00,00:00:00:00:00:00,Sun Nov 01 00:00:00 EST 0000,Sun Nov 01 00:00:00 EST 0000,"Apple, Inc.",abcd-0000abc-a,abcd-abcd-a0000-00
Here I don't want to split on Apple, .
I know there exists csv reader in python and I can use it in plpython but that's slow considering millions of such strings! I would like a pure psql method!
Here is an example of reading a CSV file with an External Table using the CSV format.
CREATE EXTERNAL TABLE ext_expenses ( name text,
date date, amount float4, category text, desc1 text )
LOCATION ('gpfdist://etlhost-1:8081/*.txt',
'gpfdist://etlhost-2:8082/*.txt')
FORMAT 'CSV' ( DELIMITER ',' )
LOG ERRORS SEGMENT REJECT LIMIT 5;
This was taken from the Greenplum docs too.
http://gpdb.docs.pivotal.io/530/admin_guide/external/g-example-4-single-gpfdist-instance-with-error-logging.html

invalid input syntax for integer with postgres

i have a table:
id | detail
1 | ddsffdfdf ;df, deef,"dgfgf",/dfdf/
when I did: insert into details values(1,'ddsffdfdf ;df, deef'); => got inserted properly
When I copied that inserted value from database to a file,the file had: 1 ddsffdfdf ;df, deef
Then I loaded the whole csv file to pgsql database,with values in the format: 1 ddsffdfdf ;df, deef
ERROR: invalid input syntax for integer: "1 ddsffdfdf ;df, deef is obtained. How to solve the problem?
CSVs need a delimiter that Postgres will recognize to break the text into respective fields. Your delimiter is a space, which is insufficient. Your CSV file should look more like:
1,"ddsffdfdf df, deef"
And your SQL should look like:
COPY details FROM 'filename' WITH CSV;
The WITH CSV is important because it tells Postgres to use a comma as the delimiter and parses your values based on that. Because your second field contains a comma, you want to enclose its value in quotes so that its comma is not mistaken for a delimiter.
To look at a good example of a properly formatted CSV file, you can output your current table:
COPY details TO '/your/filename.csv' WITH CSV;

How can I specifiy which delimiter a command line Hive query should return?

I am using command line Hive. For example hive -e "SELECT * FROM my_db.my_table;"
It is currently returning what looks like tab separated values. Is it possible to specify which delimiter it should use? For example, can I make it return pipe separated values?
what i am done in my case, i fired a query like below.
INSERT OVERWRITE LOCAL DIRECTORY '/home/Desktop/test3'
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
select * from stud_02
other solution would be
hive -e 'select * from stud_01 limit 10' | sed 's/[[:space:]]\+/,/g' >> /home/Desktop/test.csv

Delimit SQL Server output using custom string

I am running a job in MS SQL Server that outputs a text file with white space in between columns. What I'd like to do is specify a specific character sequence between each column as a delimiter.
For example, I'd like the output to look like:
Apple%%%red%%%fruit
banana%%%yellow%%%fruit
onion%%%White%%%veggie
In this example, %%% is the delimiter.
How can I do this?
Assuming that you are using the output file of the job step, and the output file is currently structured something like this:
---- --------
row1 somedata
row2 somedata
You could just concatenate the columns using '+' and fit the percent signs in as appropriate. So the job step definition would contain:
select column1 + '%%%' + column2 from table1;
And the output would look like:
---------------
row1%%%somedata
row2%%%somedata
This assumes that you are OK with concatenating each row of results into a single column. You will need to cast/convert non-character column values for this to work.
My guess is that you are looking for the T-SQL equivalent of Oracle's P/SQL command "set colsep" command. This command lets you alter the delimter of the output. TO make it semicolon, for example, you would call:
set colsep ";"
But in SQL Server... I see the way to do it.
Use the "bcp" utility and you can specify the delimiter and write to your file. He are instructions:
http://msdn.microsoft.com/en-us/library/ms162802.aspx
Look at the -t option to change the separator.

LOAD DATA LOCAL, How do I skip the first line?

I'm trying to Load a CSV file into my MySQL database,
But I would like to skip the first line.
I fact It contains the name of my columns and no interesting data.
Here is the query I'm using:
LOAD DATA LOCAL INFILE '/myfile.csv'
INTO TABLE tableName
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
(column,column,column);
LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test IGNORE 1 LINES;
(reference)
For those curious, IGNORE N LINES should be after the separator qualifiers:
LOAD DATA LOCAL INFILE '/myfile.csv'
INTO TABLE tableName
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(column,column,column);
Try this:
IGNORE N LINES
LOAD DATA INFILE "/path/to/file.csv"
INTO TABLE MYTABLE
COLUMNS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;