this.schemaManager.generateCreateTableStmt()); session.execute(this.schemaManager.generateCreateTableStmt()); log.info("Create table statement executed"); } else { this.conf.getTableName()); log.info("Using table schema: {}", schemaManager.generateCreateTableStmt()); CqlBulkOutputFormat.setTableSchema(hadoopConf, this.conf.getTableName(), schemaManager.generateCreateTableStmt());
/** * Creates a basic table in Cassandra that can be used for more testing (i.e altering) */ private void createBasicTable() { final CassandraSchema schema = new CassandraSchema(KEY_SPACE, TABLE, fields); final CassandraSinkSchemaManager schemaManager = new CassandraSinkSchemaManager( schema, Arrays.asList("country_code", "state_province"), Arrays.asList(new ClusterKey("city", ClusterKey.Order.DESC), new ClusterKey("gym_name", ClusterKey.Order.ASC))); final String createTableStmt = schemaManager.generateCreateTableStmt(); try (final Session session = getSession()) { session.execute(createTableStmt); } }
@Test public void testCreateTableWithMultiplePrimaryKeys() { final CassandraSchema schema = new CassandraSchema(KEY_SPACE, TABLE, fields); final CassandraSinkSchemaManager schemaManager = new CassandraSinkSchemaManager( schema, Arrays.asList("country_code", "state_province"), Collections.EMPTY_LIST); final String createTableStmt = schemaManager.generateCreateTableStmt(); final String expected = "CREATE TABLE IF NOT EXISTS marmaray.crossfit_gyms (country_code text," + "state_province text,city text,capacity int,gym_name text, PRIMARY KEY ((country_code,state_province))) "; Assert.assertEquals(expected, createTableStmt); try (final Session session = getSession()) { session.execute(createTableStmt); validateCreateTable(session); } }
@Test public void testCreateTableWithSinglePrimaryKeyAndNoClusteringKey() { final CassandraSchema schema = new CassandraSchema(KEY_SPACE, TABLE, fields); final CassandraSinkSchemaManager schemaManager = new CassandraSinkSchemaManager( schema, Collections.singletonList("country_code"), Collections.EMPTY_LIST); final String createTableStmt = schemaManager.generateCreateTableStmt(); final String expected = "CREATE TABLE IF NOT EXISTS marmaray.crossfit_gyms (country_code text," + "state_province text,city text,capacity int,gym_name text, PRIMARY KEY ((country_code))) "; Assert.assertEquals(expected, createTableStmt); try (final Session session = getSession()) { session.execute(createTableStmt); validateCreateTable(session); } }
@Test public void testCreateTableWithSinglePrimaryKeyAndOneClusteringKeyDesc() { final CassandraSchema schema = new CassandraSchema(KEY_SPACE, TABLE, fields); final CassandraSinkSchemaManager schemaManager = new CassandraSinkSchemaManager( schema, Collections.singletonList("country_code"), Collections.singletonList(new ClusterKey("state_province", ClusterKey.Order.DESC))); final String createTableStmt = schemaManager.generateCreateTableStmt(); final String expected = "CREATE TABLE IF NOT EXISTS marmaray.crossfit_gyms (country_code text," + "state_province text,city text,capacity int,gym_name text, PRIMARY KEY ((country_code),state_province))" + " WITH CLUSTERING ORDER BY (state_province DESC)"; Assert.assertEquals(expected, createTableStmt); try (final Session session = getSession()) { session.execute(createTableStmt); validateCreateTable(session); } }
@Test public void testCreateTableWithMultiplePrimaryKeysAndClusteringKeys() { final CassandraSchema schema = new CassandraSchema(KEY_SPACE, TABLE, fields); final CassandraSinkSchemaManager schemaManager = new CassandraSinkSchemaManager( schema, Arrays.asList("country_code", "state_province"), Arrays.asList(new ClusterKey("city", ClusterKey.Order.DESC), new ClusterKey("gym_name", ClusterKey.Order.ASC))); final String createTableStmt = schemaManager.generateCreateTableStmt(); final String expected = "CREATE TABLE IF NOT EXISTS marmaray.crossfit_gyms (country_code text," + "state_province text,city text,capacity int,gym_name text, PRIMARY KEY ((country_code,state_province)" + ",city,gym_name)) WITH CLUSTERING ORDER BY (city DESC,gym_name ASC)"; Assert.assertEquals(expected, createTableStmt); try (final Session session = getSession()) { session.execute(createTableStmt); validateCreateTable(session); } }