[ 
https://issues.apache.org/jira/browse/PHOENIX-1277?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14144707#comment-14144707
 ] 

Gabriel Reid commented on PHOENIX-1277:
---------------------------------------

This looks to be a case of inconsistent handling of rules for the CHAR type. In 
PDataType.CHAR there are a number of guards against null (or empty) values, but 
these don't seem to get hit (at least in general) via typical JDBC access. As 
has been seen, these guards are getting hit by the CSV loader.

As Carter pointed out, there are a number of ways of inserting nulls into a 
CHAR field, such as:
* doing an upsert of a new row, and not supplying a value for the CHAR field
* explicitly upserting NULL into the CHAR field via an upsert statement (i.e. 
{{upsert into dummy values (1, NULL)}})
* explicitly upserting NULL via {{PreparedStatement#setNull}}

The only way that I have found that does prevent upserting NULL into a CHAR 
field is if {{PreparedStatement#setString}} is called with an empty string for 
the CHAR field (i.e. {{prepStmt.setString(1, "")}}).

It looks to me like the best way to deal with this would be to remove the 
guards against null values in PDataType.CHAR. [~jamestaylor] does this sound 
right to you? Is there a specific reason to (attempt to) disallow nulls in CHAR 
fields? It seems as though preventing null values is something that should be 
handled elsewhere, and not as part of PDataType.

> CSVCommonsLoader not allowing null CHAR values (non PK)
> -------------------------------------------------------
>
>                 Key: PHOENIX-1277
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1277
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 5.0.0
>            Reporter: Carter Shanklin
>            Priority: Minor
>
> With this simple table:
> {code}
> create table dummy ( x integer primary key, y char(10) );
> {code}
> And dataset
> {code}
> $ cat DummyValues.csv
> 1,x
> 2,
> 3,z
> {code}
> And running psql.py I get this:
> {code}
> psql.py -t DUMMY      localhost:2181:/hbase-unsecure DummyValues.csv
> 14/09/22 16:31:02 ERROR util.CSVCommonsLoader: Error upserting record [2, ]: 
> CHAR may not be null
> CSV Upsert complete. 2 rows upserted
> Time: 0.052 sec(s)
> {code}
> In sqlline I can insert nulls just fine into column y.
> Didn't check to see if this affects other types, e.g. varchar.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to