Cassandra
  1. Cassandra
  2. CASSANDRA-5008

"show schema" command in cassandra-cli generates wrong "index_options" values.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Fix Version/s: 1.1.8, 1.2.0 rc1
    • Component/s: None
    • Labels:
      None
    • Environment:

      ubuntu 12.04

      Description

      Using cassandra-cli, launch the "show schema" command and save the output to a file.
      Try to import it in order to recreate the schema, it fails with error message :
      "Syntax error at position 626: no viable alternative at input '}'"

        Activity

        Hide
        Thierry Boileau added a comment - - edited

        After some investigations, it appears that the "index_options" attributes are badly generated when there is actually no index options :

        create column family Test
        with column_type = 'Standard'
        and comparator = 'UTF8Type'
        and default_validation_class = 'UTF8Type'
        and key_validation_class = 'UTF8Type'
        and read_repair_chance = 0.1
        and dclocal_read_repair_chance = 0.0
        and gc_grace = 864000
        and min_compaction_threshold = 4
        and max_compaction_threshold = 32
        and replicate_on_write = true
        and compaction_strategy = 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'
        and caching = 'KEYS_ONLY'
        and column_metadata = [
        {column_name : 'email',
        validation_class : UTF8Type,
        index_name : 'test_email',
        index_type : 0,
        index_options : {

        }},
        {column_name : 'enabled',
        validation_class : UTF8Type,
        index_name : 'test_enabled',
        index_type : 0,
        index_options : {

        }},
        {column_name : 'roles',
        validation_class : UTF8Type,
        index_name : 'test_roles',
        index_type : 0,
        index_options : {

        }}]

        When removing these empty "index_options" attributes, the script is correctly handled.

        Show
        Thierry Boileau added a comment - - edited After some investigations, it appears that the "index_options" attributes are badly generated when there is actually no index options : create column family Test with column_type = 'Standard' and comparator = 'UTF8Type' and default_validation_class = 'UTF8Type' and key_validation_class = 'UTF8Type' and read_repair_chance = 0.1 and dclocal_read_repair_chance = 0.0 and gc_grace = 864000 and min_compaction_threshold = 4 and max_compaction_threshold = 32 and replicate_on_write = true and compaction_strategy = 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy' and caching = 'KEYS_ONLY' and column_metadata = [ {column_name : 'email', validation_class : UTF8Type, index_name : 'test_email', index_type : 0, index_options : { }}, {column_name : 'enabled', validation_class : UTF8Type, index_name : 'test_enabled', index_type : 0, index_options : { }}, {column_name : 'roles', validation_class : UTF8Type, index_name : 'test_roles', index_type : 0, index_options : { }}] When removing these empty "index_options" attributes, the script is correctly handled.
        Hide
        Thierry Boileau added a comment -

        I guess the fix is located in method "showColumnMeta" of class "org.apache.cassandra.cli.CliClient". It could be something like this:

        if (colDef.index_options != null && !colDef.index_options.entrySet().isEmpty())
        {
        sb.append(TAB + TAB + "index_options : {"+NEWLINE);
        for (Map.Entry<String, String> entry : colDef.index_options.entrySet())

        { sb.append(TAB + TAB + TAB + CliUtils.escapeSQLString(entry.getKey()) + ": '" + CliUtils.escapeSQLString(entry.getValue()) + "'," + NEWLINE); }

        sb.append("}");
        }

        Show
        Thierry Boileau added a comment - I guess the fix is located in method "showColumnMeta" of class "org.apache.cassandra.cli.CliClient". It could be something like this: if (colDef.index_options != null && !colDef.index_options.entrySet().isEmpty()) { sb.append(TAB + TAB + "index_options : {"+NEWLINE); for (Map.Entry<String, String> entry : colDef.index_options.entrySet()) { sb.append(TAB + TAB + TAB + CliUtils.escapeSQLString(entry.getKey()) + ": '" + CliUtils.escapeSQLString(entry.getValue()) + "'," + NEWLINE); } sb.append("}"); }
        Hide
        Yuki Morishita added a comment -

        Thanks Thierry, committed your !isEmpty check in 1ac90589ead4b95a922d783ead75412dd46c0f28

        Show
        Yuki Morishita added a comment - Thanks Thierry, committed your !isEmpty check in 1ac90589ead4b95a922d783ead75412dd46c0f28

          People

          • Assignee:
            Yuki Morishita
            Reporter:
            Thierry Boileau
            Reviewer:
            Brandon Williams
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development