You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by "Petter von Dolwitz (Hem)" <pe...@gmail.com> on 2013/09/23 15:47:32 UTC

Bad Request: Invalid null value for clustering key part

I'm trying to import some rows to a table using the COPY command. I have a
PRIMARY KEY that is built up from many fields. During the import I get

Bad Request: Invalid null value for clustering key part {field_name}

Is it not permitted to have null values in a field that is part a primary
key? This seems to be ok when using the java-driver to insert row-by-row
but not when using the COPY command. Can anybody advise?

Thanks,
Petter

Re: Bad Request: Invalid null value for clustering key part

Posted by "Petter von Dolwitz (Hem)" <pe...@gmail.com>.
In fact, the blog post on the subject (
http://www.datastax.com/dev/blog/simple-data-importing-and-exporting-with-cassandra)
also states that the NULL option only is used by the COPY ... TO command
but it also states that this might change in the future and the future
seems to be here now.

Thanks,
Petter


2013/9/25 Petter von Dolwitz (Hem) <pe...@gmail.com>

> I am generating the CSV file by other means than the COPY ... TO command
> and I thought that the NULL option did not apply to the COPY ... FROM
> command but, as it turns out, it does! This solved my problem.
>
> The documentation here (
> http://www.datastax.com/documentation/cql/3.1/webhelp/index.html#cql/cql_reference/copy_r.html)
> is misleading. Should I report this by other means than this post?
>
> Thanks,
> Petter
>
>
>
>
>
> 2013/9/24 Sylvain Lebresne <sy...@datastax.com>
>
>> Oh. That would be a COPY thing then. I'm not extremely familiar with
>> cqlsh code (which COPY is part of) but looking at the online help for it,
>> it seems to have a 'NULL' option that allows to define which character is
>> used to represent nulls. And by default, it does is an empty string. So you
>> could try something like:
>>   COPY ... TO ... WITH NULL='null'
>> (assuming that if you do have nulls you use the string 'null' to encode
>> it in your csv and that your are sure nothing that's not supposed to be
>> null will be represented by the string 'null').
>>
>> --
>> Sylvain
>>
>>
>> On Tue, Sep 24, 2013 at 9:41 AM, Petter von Dolwitz (Hem) <
>> petter.von.dolwitz@gmail.com> wrote:
>>
>>> Hi Sylvain,
>>>
>>> I was not describing the problem correctly. I'm sorry for this. This is
>>> the situation:
>>>
>>> 1. I'm populating the DB with the java-driver (INSERT INTO...). Some
>>> fields that are part of the primary key is *empty strings*. This works fine.
>>> 2. I'm trying to populate the DB from a CSV (COPY ... FROM) using cqlsh.
>>> Some fields that are part of the primary key is *empty strings*. This
>>> scenario gives me the "Bad Request: Invalid null value for clustering key
>>> part {field_name}" message. Seems like empty strings are treated as NULL
>>> when using the COPY .. FROM command?
>>>
>>> This can obviously be me not knowing how to encode an empty string in a
>>> CSV file. A simplified row from the CSV file can look like below:
>>>
>>> "field1_value","","","field4_value","field5_value"
>>>
>>> whereas field1 through field4 is part of the primary key.
>>>
>>> Thanks for your time,
>>> Petter
>>>
>>>
>>>
>>>
>>> 2013/9/23 Sylvain Lebresne <sy...@datastax.com>
>>>
>>>>
>>>> Is it not permitted to have null values in a field that is part a
>>>>> primary key?
>>>>>
>>>>
>>>> It's not.
>>>>
>>>>
>>>>> This seems to be ok when using the java-driver
>>>>>
>>>>
>>>> Are you sure? Because that would qualify as a bug (in the sense that
>>>> it's not supported by C* so there is not reason why this would work with
>>>> any driver). If you have some java driver code that show it possible, I'd
>>>> be happy to have a look.
>>>>
>>>> --
>>>> Sylvain
>>>>
>>>
>>>
>>
>

Re: Bad Request: Invalid null value for clustering key part

Posted by Tyler Hobbs <ty...@datastax.com>.
On Wed, Sep 25, 2013 at 5:00 AM, Petter von Dolwitz (Hem) <
petter.von.dolwitz@gmail.com> wrote:

> I am generating the CSV file by other means than the COPY ... TO command
> and I thought that the NULL option did not apply to the COPY ... FROM
> command but, as it turns out, it does! This solved my problem.
>
> The documentation here (
> http://www.datastax.com/documentation/cql/3.1/webhelp/index.html#cql/cql_reference/copy_r.html)
> is misleading. Should I report this by other means than this post?
>

I've opened a ticket with our docs team to get this updated.  Thanks!


-- 
Tyler Hobbs
DataStax <http://datastax.com/>

Re: Bad Request: Invalid null value for clustering key part

Posted by "Petter von Dolwitz (Hem)" <pe...@gmail.com>.
I am generating the CSV file by other means than the COPY ... TO command
and I thought that the NULL option did not apply to the COPY ... FROM
command but, as it turns out, it does! This solved my problem.

The documentation here (
http://www.datastax.com/documentation/cql/3.1/webhelp/index.html#cql/cql_reference/copy_r.html)
is misleading. Should I report this by other means than this post?

Thanks,
Petter





2013/9/24 Sylvain Lebresne <sy...@datastax.com>

> Oh. That would be a COPY thing then. I'm not extremely familiar with cqlsh
> code (which COPY is part of) but looking at the online help for it, it
> seems to have a 'NULL' option that allows to define which character is used
> to represent nulls. And by default, it does is an empty string. So you
> could try something like:
>   COPY ... TO ... WITH NULL='null'
> (assuming that if you do have nulls you use the string 'null' to encode it
> in your csv and that your are sure nothing that's not supposed to be null
> will be represented by the string 'null').
>
> --
> Sylvain
>
>
> On Tue, Sep 24, 2013 at 9:41 AM, Petter von Dolwitz (Hem) <
> petter.von.dolwitz@gmail.com> wrote:
>
>> Hi Sylvain,
>>
>> I was not describing the problem correctly. I'm sorry for this. This is
>> the situation:
>>
>> 1. I'm populating the DB with the java-driver (INSERT INTO...). Some
>> fields that are part of the primary key is *empty strings*. This works fine.
>> 2. I'm trying to populate the DB from a CSV (COPY ... FROM) using cqlsh.
>> Some fields that are part of the primary key is *empty strings*. This
>> scenario gives me the "Bad Request: Invalid null value for clustering key
>> part {field_name}" message. Seems like empty strings are treated as NULL
>> when using the COPY .. FROM command?
>>
>> This can obviously be me not knowing how to encode an empty string in a
>> CSV file. A simplified row from the CSV file can look like below:
>>
>> "field1_value","","","field4_value","field5_value"
>>
>> whereas field1 through field4 is part of the primary key.
>>
>> Thanks for your time,
>> Petter
>>
>>
>>
>>
>> 2013/9/23 Sylvain Lebresne <sy...@datastax.com>
>>
>>>
>>> Is it not permitted to have null values in a field that is part a
>>>> primary key?
>>>>
>>>
>>> It's not.
>>>
>>>
>>>> This seems to be ok when using the java-driver
>>>>
>>>
>>> Are you sure? Because that would qualify as a bug (in the sense that
>>> it's not supported by C* so there is not reason why this would work with
>>> any driver). If you have some java driver code that show it possible, I'd
>>> be happy to have a look.
>>>
>>> --
>>> Sylvain
>>>
>>
>>
>

Re: Bad Request: Invalid null value for clustering key part

Posted by Sylvain Lebresne <sy...@datastax.com>.
Oh. That would be a COPY thing then. I'm not extremely familiar with cqlsh
code (which COPY is part of) but looking at the online help for it, it
seems to have a 'NULL' option that allows to define which character is used
to represent nulls. And by default, it does is an empty string. So you
could try something like:
  COPY ... TO ... WITH NULL='null'
(assuming that if you do have nulls you use the string 'null' to encode it
in your csv and that your are sure nothing that's not supposed to be null
will be represented by the string 'null').

--
Sylvain


On Tue, Sep 24, 2013 at 9:41 AM, Petter von Dolwitz (Hem) <
petter.von.dolwitz@gmail.com> wrote:

> Hi Sylvain,
>
> I was not describing the problem correctly. I'm sorry for this. This is
> the situation:
>
> 1. I'm populating the DB with the java-driver (INSERT INTO...). Some
> fields that are part of the primary key is *empty strings*. This works fine.
> 2. I'm trying to populate the DB from a CSV (COPY ... FROM) using cqlsh.
> Some fields that are part of the primary key is *empty strings*. This
> scenario gives me the "Bad Request: Invalid null value for clustering key
> part {field_name}" message. Seems like empty strings are treated as NULL
> when using the COPY .. FROM command?
>
> This can obviously be me not knowing how to encode an empty string in a
> CSV file. A simplified row from the CSV file can look like below:
>
> "field1_value","","","field4_value","field5_value"
>
> whereas field1 through field4 is part of the primary key.
>
> Thanks for your time,
> Petter
>
>
>
>
> 2013/9/23 Sylvain Lebresne <sy...@datastax.com>
>
>>
>> Is it not permitted to have null values in a field that is part a primary
>>> key?
>>>
>>
>> It's not.
>>
>>
>>> This seems to be ok when using the java-driver
>>>
>>
>> Are you sure? Because that would qualify as a bug (in the sense that it's
>> not supported by C* so there is not reason why this would work with any
>> driver). If you have some java driver code that show it possible, I'd be
>> happy to have a look.
>>
>> --
>> Sylvain
>>
>
>

Re: Bad Request: Invalid null value for clustering key part

Posted by "Petter von Dolwitz (Hem)" <pe...@gmail.com>.
Hi Sylvain,

I was not describing the problem correctly. I'm sorry for this. This is the
situation:

1. I'm populating the DB with the java-driver (INSERT INTO...). Some fields
that are part of the primary key is *empty strings*. This works fine.
2. I'm trying to populate the DB from a CSV (COPY ... FROM) using cqlsh.
Some fields that are part of the primary key is *empty strings*. This
scenario gives me the "Bad Request: Invalid null value for clustering key
part {field_name}" message. Seems like empty strings are treated as NULL
when using the COPY .. FROM command?

This can obviously be me not knowing how to encode an empty string in a CSV
file. A simplified row from the CSV file can look like below:

"field1_value","","","field4_value","field5_value"

whereas field1 through field4 is part of the primary key.

Thanks for your time,
Petter




2013/9/23 Sylvain Lebresne <sy...@datastax.com>

>
> Is it not permitted to have null values in a field that is part a primary
>> key?
>>
>
> It's not.
>
>
>> This seems to be ok when using the java-driver
>>
>
> Are you sure? Because that would qualify as a bug (in the sense that it's
> not supported by C* so there is not reason why this would work with any
> driver). If you have some java driver code that show it possible, I'd be
> happy to have a look.
>
> --
> Sylvain
>

Re: Bad Request: Invalid null value for clustering key part

Posted by Sylvain Lebresne <sy...@datastax.com>.
> Is it not permitted to have null values in a field that is part a primary
> key?
>

It's not.


> This seems to be ok when using the java-driver
>

Are you sure? Because that would qualify as a bug (in the sense that it's
not supported by C* so there is not reason why this would work with any
driver). If you have some java driver code that show it possible, I'd be
happy to have a look.

--
Sylvain