use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.
the class MappingsTableTest method test_rows.
@Test
public void test_rows() {
// given
Mapping mapping = new Mapping("table-name", "table-external-name", "table-type", emptyList(), singletonMap("key", "value"));
MappingsTable mappingTable = new MappingsTable("catalog", null, "table-schema", singletonList(mapping));
// when
List<Object[]> rows = mappingTable.rows();
// then
assertThat(rows).containsExactly(new Object[] { "catalog", "table-schema", "table-name", "table-external-name", "table-type", "{\"key\":\"value\"}" });
}
use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.
the class SqlCreateMappingTest method test_unparse.
@Test
public void test_unparse() {
Mapping mapping = new Mapping("name", "external-name", "Type", asList(new MappingField("field1", QueryDataType.VARCHAR, "__key.field1"), new MappingField("field2", QueryDataType.INT, "this.field2")), ImmutableMap.of("key1", "value1", "key2", "value2"));
String sql = SqlCreateMapping.unparse(mapping);
assertThat(sql).isEqualTo("CREATE MAPPING \"name\" EXTERNAL NAME \"external-name\" (" + LE + " \"field1\" VARCHAR EXTERNAL NAME \"__key.field1\"," + LE + " \"field2\" INTEGER EXTERNAL NAME \"this.field2\"" + LE + ")" + LE + "TYPE Type" + LE + "OPTIONS (" + LE + " 'key1' = 'value1'," + LE + " 'key2' = 'value2'" + LE + ")");
}
use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.
the class SqlCreateMappingTest method test_unparse_quoting.
@Test
public void test_unparse_quoting() {
Mapping mapping = new Mapping("na\"me", "external\"name", "Type", singletonList(new MappingField("fi\"eld", QueryDataType.VARCHAR, "__key\"field")), ImmutableMap.of("ke'y", "val'ue"));
String sql = SqlCreateMapping.unparse(mapping);
assertThat(sql).isEqualTo("CREATE MAPPING \"na\"\"me\" EXTERNAL NAME \"external\"\"name\" (" + LE + " \"fi\"\"eld\" VARCHAR EXTERNAL NAME \"__key\"\"field\"" + LE + ")" + LE + "TYPE Type" + LE + "OPTIONS (" + LE + " 'ke''y' = 'val''ue'" + LE + ")");
}
use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.
the class TablesStorageTest method when_put_then_overridesPrevious.
@Test
public void when_put_then_overridesPrevious() {
String name = randomName();
Mapping originalMapping = mapping(name, "type1");
Mapping updatedMapping = mapping(name, "type2");
storage.put(name, originalMapping);
storage.put(name, updatedMapping);
assertThat(storage.allObjects().stream().noneMatch(m -> m.equals(originalMapping)));
assertThat(storage.allObjects().stream().anyMatch(m -> m.equals(updatedMapping)));
}
use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.
the class CalciteSqlOptimizer method toCreateMappingPlan.
private SqlPlan toCreateMappingPlan(PlanKey planKey, SqlCreateMapping sqlCreateMapping) {
List<MappingField> mappingFields = sqlCreateMapping.columns().map(field -> new MappingField(field.name(), field.type(), field.externalName())).collect(toList());
Mapping mapping = new Mapping(sqlCreateMapping.nameWithoutSchema(), sqlCreateMapping.externalName(), sqlCreateMapping.type(), mappingFields, sqlCreateMapping.options());
return new CreateMappingPlan(planKey, mapping, sqlCreateMapping.getReplace(), sqlCreateMapping.ifNotExists(), planExecutor);
}
Aggregations