Search in sources :

Example 1 with SchemaRows

use of com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows in project java-driver by datastax.

the class SchemaParserTest method parse.

private MetadataRefresh parse(Consumer<CassandraSchemaRows.Builder> builderConfig) {
    CassandraSchemaRows.Builder builder = new CassandraSchemaRows.Builder(NODE_3_0, keyspaceFilter, "test");
    builderConfig.accept(builder);
    SchemaRows rows = builder.build();
    return new CassandraSchemaParser(rows, context).parse();
}
Also used : CassandraSchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.CassandraSchemaRows) CassandraSchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.CassandraSchemaRows) SchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows)

Example 2 with SchemaRows

use of com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows in project java-driver by datastax.

the class ViewParserTest method should_parse_view.

@Test
public void should_parse_view() {
    SchemaRows rows = rows(VIEW_ROW_3_0, COLUMN_ROWS_3_0);
    ViewParser parser = new ViewParser(rows, context);
    ViewMetadata view = parser.parseView(VIEW_ROW_3_0, KEYSPACE_ID, Collections.emptyMap());
    assertThat(view.getKeyspace().asInternal()).isEqualTo("ks");
    assertThat(view.getName().asInternal()).isEqualTo("alltimehigh");
    assertThat(view.getBaseTable().asInternal()).isEqualTo("scores");
    assertThat(view.getPartitionKey()).hasSize(1);
    ColumnMetadata pk0 = view.getPartitionKey().get(0);
    assertThat(pk0.getName().asInternal()).isEqualTo("game");
    assertThat(pk0.getType()).isEqualTo(DataTypes.TEXT);
    assertThat(view.getClusteringColumns().entrySet()).hasSize(5);
    Iterator<ColumnMetadata> clusteringColumnsIterator = view.getClusteringColumns().keySet().iterator();
    assertThat(clusteringColumnsIterator.next().getName().asInternal()).isEqualTo("score");
    assertThat(clusteringColumnsIterator.next().getName().asInternal()).isEqualTo("user");
    assertThat(clusteringColumnsIterator.next().getName().asInternal()).isEqualTo("year");
    assertThat(clusteringColumnsIterator.next().getName().asInternal()).isEqualTo("month");
    assertThat(clusteringColumnsIterator.next().getName().asInternal()).isEqualTo("day");
    assertThat(view.getColumns()).containsOnlyKeys(CqlIdentifier.fromInternal("game"), CqlIdentifier.fromInternal("score"), CqlIdentifier.fromInternal("user"), CqlIdentifier.fromInternal("year"), CqlIdentifier.fromInternal("month"), CqlIdentifier.fromInternal("day"));
}
Also used : ColumnMetadata(com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata) CassandraSchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.CassandraSchemaRows) SchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows) ViewMetadata(com.datastax.oss.driver.api.core.metadata.schema.ViewMetadata) Test(org.junit.Test)

Example 3 with SchemaRows

use of com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows in project java-driver by datastax.

the class TableParserTest method should_parse_legacy_tables.

@Test
public void should_parse_legacy_tables() {
    SchemaRows rows = legacyRows(TABLE_ROW_2_2, COLUMN_ROWS_2_2);
    TableParser parser = new TableParser(rows, context);
    TableMetadata table = parser.parseTable(TABLE_ROW_2_2, KEYSPACE_ID, Collections.emptyMap());
    checkTable(table);
    assertThat(table.getOptions().get(CqlIdentifier.fromInternal("caching"))).isEqualTo("{\"keys\":\"ALL\", \"rows_per_partition\":\"NONE\"}");
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) CassandraSchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.CassandraSchemaRows) SchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows) Test(org.junit.Test)

Example 4 with SchemaRows

use of com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows in project java-driver by datastax.

the class TableParserTest method should_skip_when_no_column_rows.

@Test
public void should_skip_when_no_column_rows() {
    SchemaRows rows = legacyRows(TABLE_ROW_2_2, Collections.emptyList());
    TableParser parser = new TableParser(rows, context);
    TableMetadata table = parser.parseTable(TABLE_ROW_2_2, KEYSPACE_ID, Collections.emptyMap());
    assertThat(table).isNull();
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) CassandraSchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.CassandraSchemaRows) SchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows) Test(org.junit.Test)

Example 5 with SchemaRows

use of com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows in project java-driver by datastax.

the class TableParserTest method should_parse_read_repair_and_additional_write_policy.

/**
 * Covers two additional Cassandra 4.0 options added in JAVA-2090.
 */
@Test
public void should_parse_read_repair_and_additional_write_policy() {
    AdminRow tableRow40 = mockModernTableRow("ks", "foo");
    when(tableRow40.get("read_repair", TypeCodecs.TEXT)).thenReturn("NONE");
    when(tableRow40.get("additional_write_policy", TypeCodecs.TEXT)).thenReturn("40p");
    SchemaRows rows = modernRows(tableRow40, COLUMN_ROWS_3_0, INDEX_ROWS_3_0);
    TableParser parser = new TableParser(rows, context);
    TableMetadata table = parser.parseTable(tableRow40, KEYSPACE_ID, Collections.emptyMap());
    checkTable(table);
    assertThat(table.getOptions()).containsEntry(CqlIdentifier.fromInternal("read_repair"), "NONE").containsEntry(CqlIdentifier.fromInternal("additional_write_policy"), "40p");
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) CassandraSchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.CassandraSchemaRows) SchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows) Test(org.junit.Test)

Aggregations

CassandraSchemaRows (com.datastax.oss.driver.internal.core.metadata.schema.queries.CassandraSchemaRows)7 SchemaRows (com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows)7 Test (org.junit.Test)6 TableMetadata (com.datastax.oss.driver.api.core.metadata.schema.TableMetadata)4 ViewMetadata (com.datastax.oss.driver.api.core.metadata.schema.ViewMetadata)2 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)1 AdminRow (com.datastax.oss.driver.internal.core.adminrequest.AdminRow)1 ImmutableMap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)1 Map (java.util.Map)1