/** * Ensures that if a table is configured with change data capture enabled that {@link * TableOptionsMetadata#isCDC()} returns true for that table. * * @test_category metadata * @jira_ticket JAVA-1287 * @jira_ticket CASSANDRA-12041 */ @Test(groups = "short") public void should_parse_cdc_from_table_options() { // given // create a simple table with cdc as true. String cql = String.format( "CREATE TABLE %s.cdc_table (\n" + " k text,\n" + " c int,\n" + " v timeuuid,\n" + " PRIMARY KEY (k, c)\n" + ") WITH cdc=true;", keyspace); session().execute(cql); // when retrieving the table's metadata. TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("cdc_table"); // then the table's options should have cdc as true. assertThat(table.getOptions().isCDC()).isEqualTo(true); assertThat(table.asCQLQuery(true)).contains("cdc = true"); } }
@Test(groups = "short") public void should_escape_single_quote_table_comment() { // given String cql = String.format( "CREATE TABLE %s.single_quote (\n" + " c1 int PRIMARY KEY\n" + ") WITH comment = 'comment with single quote '' should work'", keyspace); // when session().execute(cql); TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("single_quote"); // then assertThat(table.getOptions().getComment()) .isEqualTo("comment with single quote ' should work"); assertThat(table.asCQLQuery()).contains("comment = 'comment with single quote '' should work'"); }
/** * Returns a CQL query representing this table. * * This method returns a single 'CREATE TABLE' query with the options * corresponding to this table definition. * * Note that the returned string is a single line; the returned query * is not formatted in any way. * * @return the 'CREATE TABLE' query corresponding to this table. * @see #exportAsString */ public String asCQLQuery() { return asCQLQuery(false); }
/** * Validates that columns using the duration type are properly represented in {@link * TableMetadata}. * * @jira_ticket JAVA-1347 * @test_category metadata */ @Test(groups = "short") public void should_parse_column_metadata() { // column metadata TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("test_duration"); assertThat(table.getColumn("c1")).hasType(DataType.duration()); assertThat(table.asCQLQuery()).contains("c1 duration"); } }
assertThat(tm.getOptions()).isNull(); assertThat(tm.getKeyspace()).isEqualTo(km); assertThat(tm.asCQLQuery()) .isEqualTo( "/* VIRTUAL TABLE system_views.clients (address inet, port int, "
.hasColumn(c6) .hasColumn(c7); assertThat(table1.asCQLQuery()).startsWith(cql1); assertThat(table2) .hasColumn(c1) .hasColumn(c6) .hasColumn(c7); assertThat(table2.asCQLQuery()).startsWith(cql2); execute( "DROP TABLE \"MyTable1\"", "DROP TABLE \"MyTable2\"", table1.asCQLQuery(), table2.asCQLQuery());
/** * Returns a {@code String} containing CQL queries representing this * table and the index on it. * * In other words, this method returns the queries that would allow you to * recreate the schema of this table, along with the index defined on * columns of this table. * * Note that the returned String is formatted to be human readable (for * some definition of human readable at least). * * @return the CQL queries representing this table schema as a {code * String}. */ public String exportAsString() { StringBuilder sb = new StringBuilder(); sb.append(asCQLQuery(true)); for (ColumnMetadata column : columns.values()) { ColumnMetadata.IndexMetadata index = column.getIndex(); if (index == null) continue; sb.append('\n').append(index.asCQLQuery()); } return sb.toString(); }
assertThat(table.asCQLQuery()) .contains("read_repair_chance = 0.5") .contains("dclocal_read_repair_chance = 0.6") assertThat(table.asCQLQuery()) .contains("read_repair_chance = 0.5") .contains("dclocal_read_repair_chance = 0.6") assertThat(table.asCQLQuery()) .contains("read_repair_chance = 0.5") .contains("dclocal_read_repair_chance = 0.6") assertThat(table.asCQLQuery()) .contains("read_repair_chance = 0.5") .contains("dclocal_read_repair_chance = 0.6") assertThat(table.asCQLQuery()) .contains("read_repair_chance = 0.5") .contains("dclocal_read_repair_chance = 0.6")
/** * Ensures that if a table is configured with change data capture enabled that {@link * TableOptionsMetadata#isCDC()} returns true for that table. * * @test_category metadata * @jira_ticket JAVA-1287 * @jira_ticket CASSANDRA-12041 */ @Test(groups = "short") public void should_parse_cdc_from_table_options() { // given // create a simple table with cdc as true. String cql = String.format( "CREATE TABLE %s.cdc_table (\n" + " k text,\n" + " c int,\n" + " v timeuuid,\n" + " PRIMARY KEY (k, c)\n" + ") WITH cdc=true;", keyspace); session().execute(cql); // when retrieving the table's metadata. TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("cdc_table"); // then the table's options should have cdc as true. assertThat(table.getOptions().isCDC()).isEqualTo(true); assertThat(table.asCQLQuery(true)).contains("cdc = true"); } }
@Test(groups = "short") public void should_escape_single_quote_table_comment() { // given String cql = String.format( "CREATE TABLE %s.single_quote (\n" + " c1 int PRIMARY KEY\n" + ") WITH comment = 'comment with single quote '' should work'", keyspace); // when session().execute(cql); TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("single_quote"); // then assertThat(table.getOptions().getComment()) .isEqualTo("comment with single quote ' should work"); assertThat(table.asCQLQuery()).contains("comment = 'comment with single quote '' should work'"); }
/** * Validates that columns using the duration type are properly represented in {@link * TableMetadata}. * * @jira_ticket JAVA-1347 * @test_category metadata */ @Test(groups = "short") public void should_parse_column_metadata() { // column metadata TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("test_duration"); assertThat(table.getColumn("c1")).hasType(DataType.duration()); assertThat(table.asCQLQuery()).contains("c1 duration"); } }
+ " PRIMARY KEY (keyspace_name, table_name, task_id)\n" + ") */"); assertThat(tm.asCQLQuery()) .isEqualTo( "/* VIRTUAL TABLE system_views.sstable_tasks (keyspace_name text, "
assertThat(table.asCQLQuery(true)).doesNotContain("nodesync");
assertThat(table.getOptions().getNodeSync()).isEqualTo(expectedNodeSync); assertThat(table.asCQLQuery(true)) .contains("nodesync = { ", "'enabled' : 'true'", "'deadline_target_sec' : 86400");
.hasColumn(c6) .hasColumn(c7); assertThat(table1.asCQLQuery()).startsWith(cql1); assertThat(table2) .hasColumn(c1) .hasColumn(c6) .hasColumn(c7); assertThat(table2.asCQLQuery()).startsWith(cql2); execute( "DROP TABLE \"MyTable1\"", "DROP TABLE \"MyTable2\"", table1.asCQLQuery(), table2.asCQLQuery());
assertThat(table.asCQLQuery()) .contains("read_repair_chance = 0.5") .contains("dclocal_read_repair_chance = 0.6") assertThat(table.asCQLQuery()) .contains("read_repair_chance = 0.5") .contains("dclocal_read_repair_chance = 0.6") assertThat(table.asCQLQuery()) .contains("read_repair_chance = 0.5") .contains("dclocal_read_repair_chance = 0.6") assertThat(table.asCQLQuery()) .contains("read_repair_chance = 0.5") .contains("dclocal_read_repair_chance = 0.6") assertThat(table.asCQLQuery()) .contains("read_repair_chance = 0.5") .contains("dclocal_read_repair_chance = 0.6")