Search code examples
cassandraapache-pigcql3

Examples for output_query with PIG and Cassandra CqlStorage


I am trying to write data to Cassandra CQL 3 Table using:

STORE G INTO 'cql://keyapse/col_family?output_query=not sure what goes here' USING CqlStorage();

What does the output_query look like:

UPDATE col_family SET col1=$0, col2=$3 WHERE KEY=$2


Solution

  • You need to take care on both: the storage URL and the data preparation. This is an example that should work.

    Suppose you need to insert data in the following structure:

    CREATE TABLE example (
      row_id text PRIMARY KEY,
    
      value1 text,
    
      value2 int
    );

    You need to prepare the data like this:

    data_to_insert = FOREACH some_set_of_data GENERATE 
    
        TOTUPLE(TOTUPLE('row_id',row_id)), TOTUPLE(value1, value2) ;

    Finally the storing statement will be:

    STORE data_to_insert INTO 'cql://my/example?output_query=update example set value1 @ # , value2 @ #' USING CqlStorage();