use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataResolversTest method test_resolveAndValidateFields.
@Test
public void test_resolveAndValidateFields() {
// given
Map<String, String> options = ImmutableMap.of(OPTION_FORMAT, FORMAT, OPTION_PATH, "/path", OPTION_GLOB, "*");
given(resolver.resolveAndValidateFields(emptyList(), options)).willReturn(singletonList(new MappingField("field", QueryDataType.VARCHAR)));
// when
List<MappingField> resolvedFields = resolvers.resolveAndValidateFields(emptyList(), options);
// then
assertThat(resolvedFields).containsOnly(new MappingField("field", QueryDataType.VARCHAR));
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class TestAbstractSqlConnector method resolveAndValidateFields.
@Nonnull
@Override
public List<MappingField> resolveAndValidateFields(@Nonnull NodeEngine nodeEngine, @Nonnull Map<String, String> options, @Nonnull List<MappingField> userFields) {
if (userFields.size() > 0) {
throw QueryException.error("Don't specify external fields, they are fixed");
}
String[] names = options.get(OPTION_NAMES).split(DELIMITER);
String[] types = options.get(OPTION_TYPES).split(DELIMITER);
assert names.length == types.length;
List<MappingField> fields = new ArrayList<>(names.length);
for (int i = 0; i < names.length; i++) {
fields.add(new MappingField(names[i], resolveTypeForTypeFamily(QueryDataTypeFamily.valueOf(types[i]))));
}
return fields;
}
use of com.hazelcast.sql.impl.schema.MappingField 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.MappingField 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.MappingField 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