/** * Build an IndexMetadata from a legacy layout (index information is stored along with indexed * column). */ static IndexMetadata fromLegacy(ColumnMetadata column, ColumnMetadata.Raw raw) { Map<String, String> indexColumns = raw.indexColumns; if (indexColumns.isEmpty()) return null; String type = indexColumns.get(ColumnMetadata.INDEX_TYPE); if (type == null) return null; String indexName = indexColumns.get(ColumnMetadata.INDEX_NAME); String kindStr = indexColumns.get(ColumnMetadata.INDEX_TYPE); Kind kind = kindStr == null ? null : Kind.valueOf(kindStr); // Special case check for the value of the index_options column being a string with value 'null' // as this // column appears to be set this way (JAVA-834). String indexOptionsCol = indexColumns.get(ColumnMetadata.INDEX_OPTIONS); Map<String, String> options; if (indexOptionsCol == null || indexOptionsCol.isEmpty() || indexOptionsCol.equals("null")) { options = ImmutableMap.of(); } else { options = SimpleJSONParser.parseStringMap(indexOptionsCol); } String target = targetFromLegacyOptions(column, options); return new IndexMetadata((TableMetadata) column.getParent(), indexName, kind, target, options); }
public ColumnMetadataAssert isPrimaryKey() { assertThat(actual.getParent().getPrimaryKey().contains(actual)) .as("Expecting %s to be part of the primary key, but it was not", actual) .isTrue(); return this; }
public ColumnMetadataAssert isPartitionKey() { assertThat(actual.getParent().getPartitionKey().contains(actual)) .as("Expecting %s to be part of the partition key, but it was not", actual) .isTrue(); return this; }
public ColumnMetadataAssert isClusteringColumn() { assertThat(actual.getParent().getClusteringColumns().contains(actual)) .as("Expecting %s to be a clustering column, but it was not", actual) .isTrue(); return this; }
public ColumnMetadataAssert isRegularColumn() { assertThat(actual.getParent().getPrimaryKey().contains(actual)) .as("Expecting %s to be a regular column, but it was not", actual) .isFalse(); return this; }
@Test(groups = "short") public void should_create_metadata_for_simple_index() { String createValuesIndex = String.format("CREATE INDEX text_column_index ON %s.indexing (text_column);", keyspace); session().execute(createValuesIndex); ColumnMetadata column = getColumn("text_column"); IndexMetadata index = getIndex("text_column_index"); assertThat(index) .hasName("text_column_index") .hasParent((TableMetadata) column.getParent()) .isNotCustomIndex() .hasTarget("text_column") .hasKind(COMPOSITES) .asCqlQuery(createValuesIndex); assertThat((TableMetadata) column.getParent()).hasIndex(index); }
@Test(groups = "short") @CassandraVersion("2.1.3") public void should_create_metadata_for_full_index_on_set() { String createFullIndex = String.format("CREATE INDEX set_full_index ON %s.indexing (full(set_full));", keyspace); session().execute(createFullIndex); ColumnMetadata column = getColumn("set_full"); IndexMetadata index = getIndex("set_full_index"); assertThat(index) .hasName("set_full_index") .hasParent((TableMetadata) column.getParent()) .isNotCustomIndex() .hasTarget("full(set_full)") .hasKind(COMPOSITES) .asCqlQuery(createFullIndex); assertThat((TableMetadata) column.getParent()).hasIndex(index); }
@Test(groups = "short") @CassandraVersion("2.1.0") public void should_create_metadata_for_index_on_map_keys() { String createKeysIndex = String.format("CREATE INDEX map_keys_index ON %s.indexing (keys(map_keys));", keyspace); session().execute(createKeysIndex); ColumnMetadata column = getColumn("map_keys"); IndexMetadata index = getIndex("map_keys_index"); assertThat(index) .hasName("map_keys_index") .hasParent((TableMetadata) column.getParent()) .isNotCustomIndex() .hasTarget("keys(map_keys)") .hasKind(COMPOSITES) .asCqlQuery(createKeysIndex); assertThat((TableMetadata) column.getParent()).hasIndex(index); }
@Test(groups = "short") @CassandraVersion("2.1.3") public void should_create_metadata_for_full_index_on_map() { String createFullIndex = String.format("CREATE INDEX map_full_index ON %s.indexing (full(map_full));", keyspace); session().execute(createFullIndex); ColumnMetadata column = getColumn("map_full"); IndexMetadata index = getIndex("map_full_index"); assertThat(index) .hasName("map_full_index") .hasParent((TableMetadata) column.getParent()) .isNotCustomIndex() .hasTarget("full(map_full)") .hasKind(COMPOSITES) .asCqlQuery(createFullIndex); assertThat((TableMetadata) column.getParent()).hasIndex(index); }
@Test(groups = "short") @CassandraVersion("2.1.3") public void should_create_metadata_for_full_index_on_list() { String createFullIndex = String.format("CREATE INDEX list_full_index ON %s.indexing (full(list_full));", keyspace); session().execute(createFullIndex); ColumnMetadata column = getColumn("list_full"); IndexMetadata index = getIndex("list_full_index"); assertThat(index) .hasName("list_full_index") .hasParent((TableMetadata) column.getParent()) .isNotCustomIndex() .hasTarget("full(list_full)") .hasKind(COMPOSITES) .asCqlQuery(createFullIndex); assertThat((TableMetadata) column.getParent()).hasIndex(index); }
@Test(groups = "short") @CassandraVersion("2.2.0") public void should_create_metadata_for_index_on_map_entries() { String createEntriesIndex = String.format( "CREATE INDEX map_entries_index ON %s.indexing (entries(map_entries));", keyspace); session().execute(createEntriesIndex); ColumnMetadata column = getColumn("map_entries"); IndexMetadata index = getIndex("map_entries_index"); assertThat(index) .hasName("map_entries_index") .hasParent((TableMetadata) column.getParent()) .isNotCustomIndex() .hasTarget("entries(map_entries)") .hasKind(COMPOSITES) .asCqlQuery(createEntriesIndex); assertThat((TableMetadata) column.getParent()).hasIndex(index); }
@Test(groups = "short") @CassandraVersion("3.0") public void should_allow_multiple_indexes_on_map_column() { String createEntriesIndex = String.format( "CREATE INDEX map_all_entries_index ON %s.indexing (entries(map_all));", keyspace); session().execute(createEntriesIndex); String createKeysIndex = String.format("CREATE INDEX map_all_keys_index ON %s.indexing (keys(map_all));", keyspace); session().execute(createKeysIndex); String createValuesIndex = String.format( "CREATE INDEX map_all_values_index ON %s.indexing (values(map_all));", keyspace); session().execute(createValuesIndex); ColumnMetadata column = getColumn("map_all"); TableMetadata table = (TableMetadata) column.getParent(); assertThat(getIndex("map_all_entries_index")).hasParent(table).asCqlQuery(createEntriesIndex); assertThat(getIndex("map_all_keys_index")).hasParent(table).asCqlQuery(createKeysIndex); assertThat(getIndex("map_all_values_index")).hasParent(table).asCqlQuery(createValuesIndex); }
@Test(groups = "short") @CassandraVersion("2.1.0") public void should_create_metadata_for_index_on_map_values() { // 3.0 assumes the 'values' keyword if index on a collection String createValuesIndex = ccm().getCassandraVersion().getMajor() > 2 ? String.format( "CREATE INDEX map_values_index ON %s.indexing (values(map_values));", keyspace) : String.format("CREATE INDEX map_values_index ON %s.indexing (map_values);", keyspace); session().execute(createValuesIndex); ColumnMetadata column = getColumn("map_values"); IndexMetadata index = getIndex("map_values_index"); assertThat(index) .hasName("map_values_index") .hasParent((TableMetadata) column.getParent()) .isNotCustomIndex() .hasTarget(ccm().getCassandraVersion().getMajor() > 2 ? "values(map_values)" : "map_values") .hasKind(COMPOSITES) .asCqlQuery(createValuesIndex); assertThat((TableMetadata) column.getParent()).hasIndex(index); }
assertThat(cm.getParent()).isEqualTo(tm); assertThat(cm.getType()).isEqualTo(DataType.text()); assertThat(cm.getName()).isEqualTo("driver_name");
@Test(groups = "short") @CassandraVersion( value = "2.1", description = "index names with quoted identifiers and collection indexes not supported until 2.1") public void should_create_metadata_for_values_index_on_mixed_case_column() { // 3.0 assumes the 'values' keyword if index on a collection String createValuesIndex = ccm().getCassandraVersion().getMajor() > 2 ? String.format( "CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (values(\"MixedCaseColumn\"));", keyspace) : String.format( "CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (\"MixedCaseColumn\");", keyspace); session().execute(createValuesIndex); ColumnMetadata column = getColumn("\"MixedCaseColumn\""); IndexMetadata index = getIndex("\"MixedCaseIndex\""); assertThat(index) .hasName("MixedCaseIndex") .hasParent((TableMetadata) column.getParent()) .isNotCustomIndex() .hasTarget( ccm().getCassandraVersion().getMajor() > 2 ? "values(\"MixedCaseColumn\")" : "\"MixedCaseColumn\"") .hasKind(COMPOSITES) .asCqlQuery(createValuesIndex); assertThat((TableMetadata) column.getParent()).hasIndex(index); }
public ColumnMetadataAssert isPrimaryKey() { assertThat(actual.getParent().getPrimaryKey().contains(actual)) .as("Expecting %s to be part of the primary key, but it was not", actual) .isTrue(); return this; }
public ColumnMetadataAssert isClusteringColumn() { assertThat(actual.getParent().getClusteringColumns().contains(actual)) .as("Expecting %s to be a clustering column, but it was not", actual) .isTrue(); return this; }
public ColumnMetadataAssert isPartitionKey() { assertThat(actual.getParent().getPartitionKey().contains(actual)) .as("Expecting %s to be part of the partition key, but it was not", actual) .isTrue(); return this; }