Joinutility seperatorLogin utility separator Infobright.com
   
 
Problem in set @bh_dataformat = ‘txt_variable’ mode when exporting data
Posted: 30 August 2010 07:38 AM   Ignore ]  
Newbie
Rank
Total Posts:  31
Joined  2010-07-31

CREATE TABLE temp_27(C_1 VARCHAR(1000),C_2 VARCHAR(1000),C_3 BIGINT) ENGINE=BRIGHTHOUSE;

tempin.txt

test^test^1
test^test^2
test^test^3

set @bh_dataformat = ‘txt_variable’

LOAD DATA INFILE ‘E:/testdata/tempfile/tempin.txt’ INTO TABLE temp_27 FIELDS TERMINATED BY ‘^’ OPTIONALLY ENCLOSED BY ‘’ ESCAPED BY ‘’ LINES TERMINATED BY ‘
’ (C_1,C_2,C_3)

SELECT C_1,C_2,C_3 FROM temp_27 INTO OUTFILE ‘D:/sdhetl/outfile.txt’ FIELDS TERMINATED BY ‘^’

ERROR


The outfile.txt has varchar values padded to 1000 characters(which is the size of C_1 and C_2 columns), when the actual values(test) are of length 4 only.

I shall be grateful for any suggestions.

[ Edited: 30 August 2010 09:31 AM by Buddoda!]
Profile
 
Posted: 30 August 2010 09:05 AM   Ignore ]   [ # 1 ]  
Sr. Member
Avatar
RankRankRankRank
Total Posts:  738
Joined  2008-08-18
Buddoda! - 30 August 2010 07:38 AM

ERROR

The outfile.txt has varchar values padded to 1000 characters ...

buddoda!

I ran your test scenario on IEE 3.4.2 GA on CentOS 5 and didn’t receive the same results.  In my output file the VARCHAR fields were only 4 bytes long and enclosed in double-quotes.  Here is my session information for comparison:

[root@localhost tmp]# more tempin.txt
test;test;1
test
;test;2
test
;test;
mysqlCREATE TABLE temp_27(
    -> 
C_1 VARCHAR(1000),
    -> 
C_2 VARCHAR(1000),
    -> 
C_3 BIGINTENGINE=BRIGHTHOUSE;
Query OK0 rows affected (0.18 sec)

mysqlset @bh_dataformat='txt_variable';
Query OK0 rows affected (0.00 sec)

mysqlLOAD DATA INFILE '/tmp/tempin.txt' INTO TABLE temp_27 FIELDS TERMINATED BY ';' ENCLOSED BY '';
Query OK3 rows affected (1.76 sec)
Records3  Deleted0  Skipped0  Warnings0

mysql
select from temp_27;
+------+------+------+
C_1  C_2  C_3  |
+------+------+------+
test test |    |
test test |    |
test test |    |
+------+------+------+
3 rows in set (0.00 sec)

mysqlselect length(C_1from temp_27 where C_3 1;
+-------------+
length(C_1) |
+-------------+
|           
|
+-------------+
1 row in set (0.00 sec)

mysqlSELECT FROM temp_27 INTO OUTFILE '/tmp/tempout.txt' FIELDS TERMINATED BY ';' ENCLOSED BY '';
Query OK3 rows affected (0.01 sec
[root@localhost tmp]# more tempout.txt
"test";"test";1
"test";"test";2
"test";"test";

One thing I notice in your post, and this might just be a typographical or copy-and-paste error, is that the LOAD statement says FIELDS TERMINATED BY ‘^’ while the data file’s values are actually separated by semi-colons (;).  I don’t know if that’s a possible issue because when I use the same syntax, I receive:

mysqlLOAD DATA INFILE '/tmp/tempin.txt' INTO TABLE temp_27 FIELDS TERMINATED BY '^' OPTIONALLY ENCLOSED BY '' ESCAPED BY '' LINES TERMINATED BY '\n' (C_1,C_2,C_3);
ERROR 2 (HY000): Wrong data or column definitionRow1field1. 

I suggest you re-try using the syntax I have used above and let us know how it works out.

PS Also review Chapter 6, Character Set Support, page 40 of the User Guide, section on Padding for more information on how Infobright handles padding in querying and loading.

Signature 
Profile
 
Posted: 30 August 2010 09:39 AM   Ignore ]   [ # 2 ]  
Newbie
Rank
Total Posts:  31
Joined  2010-07-31

Forgive(I make sure I don’t roll this) me I missed to mention the actual part in a hurry to simplify my problem, I just mentioned the actual scenario that I have faced the problem with. And I am using the versions infobright-3.4.2-win_32-ice and infobright-3.4.2-win_64-ice


SELECT IFNULL(C_1,‘NONE’),IFNULL(C_2,‘NONE’),C_3 FROM temp_tt INTO OUTFILE ‘E:/outfile.txt’ FIELDS TERMINATED BY ‘^’

[ Edited: 30 August 2010 09:45 AM by Buddoda!]
Profile
 
Posted: 30 August 2010 11:54 AM   Ignore ]   [ # 3 ]  
Sr. Member
Avatar
RankRankRankRank
Total Posts:  738
Joined  2008-08-18

Buddoda!

I re-ran the export using the IFNULL() function and received similar results - the output file padded the VARCHAR fields with white space out to 1,000 bytes.

mysqlSELECT IFNULL(C_1,'NONE'), IFNULL(C_2,'NONE'), C_3
    
-> FROM temp_27 INTO OUTFILE '/tmp/ifnullout.txt'
    
-> FIELDS TERMINATED BY '^';
Query OK3 rows affected (0.00 sec
[root@localhost tmp]# head -1 ifnullout.txt 
"test                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "^"test                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    "^1
[root
@localhost tmp]

Running the IFNULL() function alone does not exhibit this behavior, and exporting just the actual data does not exhibit this behavior, so it appears to be some combination of the export statement and the IFNULL() function.

mysqlselect ifnull(C_1,'none'from temp_27;
+--------------------+
ifnull(C_1,'none') |
+--------------------+
test               |
test               |
test               |
+--------------------+
3 rows in set (0.02 sec)

mysqlselect length(ifnull(C_1,'none')) from temp_27;
+----------------------------+
length(ifnull(C_1,'none')) |
+----------------------------+
|                          
|
|                          
|
|                          
|
+----------------------------+
3 rows in set (0.00 sec

Please feel free to log this with our Help Desk for an explanation.

Signature 
Profile
 
Posted: 08 November 2010 03:50 PM   Ignore ]   [ # 4 ]  
Sr. Member
Avatar
RankRankRankRank
Total Posts:  505
Joined  2008-08-18

Hi,

This does appear to be a bug. I’ll open a ticket.

Thanks
Geoffrey

Signature 
Profile