} else { log.info("Generating alter table statements for any columns not found"); this.schemaManager.generateAlterTableStmt(columnNames).forEach(stmt -> { log.info("Executing statement: {}", stmt); session.execute(stmt);
@Test public void testAlterTableWithOneMultipleColumns() { createBasicTable(); final List<CassandraSchemaField> joinedList = Lists.newArrayList(Iterables.concat(fields, newFields)); final CassandraSchema schema = new CassandraSchema(KEY_SPACE, TABLE, joinedList); 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 List<String> alterTableQueries = schemaManager.generateAlterTableStmt(fields.stream().map(f -> f.getFieldName()).collect(Collectors.toList())); Assert.assertTrue(alterTableQueries.size() == 2); Assert.assertEquals("ALTER TABLE marmaray.crossfit_gyms ADD new_field1 text", alterTableQueries.get(0)); Assert.assertEquals("ALTER TABLE marmaray.crossfit_gyms ADD new_field2 text", alterTableQueries.get(1)); try (final Session session = getSession()) { alterTableQueries.stream().forEach(query -> session.execute(query)); validateAlterTable(session, newFields.stream().map(f -> f.getFieldName()).collect(Collectors.toList())); } }
@Test public void testAlterTableWithOneNewColumn() { createBasicTable(); final List<CassandraSchemaField> joinedList = Lists.newArrayList(Iterables.concat(fields, Collections.singletonList(new CassandraSchemaField("new_field1", "text")))); final CassandraSchema schema = new CassandraSchema(KEY_SPACE, TABLE, joinedList); 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 List<String> alterTableQueries = schemaManager.generateAlterTableStmt(fields.stream().map(f -> f.getFieldName()).collect(Collectors.toList())); Assert.assertTrue(alterTableQueries.size() == 1); Assert.assertEquals("ALTER TABLE marmaray.crossfit_gyms ADD new_field1 text", alterTableQueries.get(0)); try (final Session session = getSession()) { alterTableQueries.stream().forEach(query -> session.execute(query)); validateAlterTable(session, Collections.singletonList("new_field1")); } }