Search in sources :

Example 36 with MappingField

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));
}
Also used : MappingField(com.hazelcast.sql.impl.schema.MappingField) Test(org.junit.Test)

Example 37 with MappingField

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;
}
Also used : ArrayList(java.util.ArrayList) MappingField(com.hazelcast.sql.impl.schema.MappingField) Nonnull(javax.annotation.Nonnull)

Example 38 with MappingField

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 + ")");
}
Also used : Mapping(com.hazelcast.sql.impl.schema.Mapping) MappingField(com.hazelcast.sql.impl.schema.MappingField) Test(org.junit.Test)

Example 39 with MappingField

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 + ")");
}
Also used : Mapping(com.hazelcast.sql.impl.schema.Mapping) MappingField(com.hazelcast.sql.impl.schema.MappingField) Test(org.junit.Test)

Example 40 with MappingField

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);
}
Also used : SelectByKeyMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.SelectByKeyMapPhysicalRel) DropViewPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DropViewPlan) SelectPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.SelectPlan) SqlCreateIndex(com.hazelcast.jet.sql.impl.parse.SqlCreateIndex) CreateDagVisitor(com.hazelcast.jet.sql.impl.opt.physical.CreateDagVisitor) Operation(org.apache.calcite.rel.core.TableModify.Operation) SqlRowMetadata(com.hazelcast.sql.SqlRowMetadata) QueryParameterMetadata(com.hazelcast.sql.impl.QueryParameterMetadata) Collections.singletonList(java.util.Collections.singletonList) AbstractMapTable(com.hazelcast.sql.impl.schema.map.AbstractMapTable) SlidingWindow(com.hazelcast.jet.sql.impl.opt.SlidingWindow) TableModify(org.apache.calcite.rel.core.TableModify) QueryUtils(com.hazelcast.sql.impl.QueryUtils) OptimizationTask(com.hazelcast.sql.impl.optimizer.OptimizationTask) CreateJobPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateJobPlan) CreateMappingPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateMappingPlan) RootRel(com.hazelcast.jet.sql.impl.opt.physical.RootRel) RelTraitSet(org.apache.calcite.plan.RelTraitSet) DropMappingPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DropMappingPlan) SqlOptimizer(com.hazelcast.sql.impl.optimizer.SqlOptimizer) RelVisitor(org.apache.calcite.rel.RelVisitor) IMapUpdatePlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapUpdatePlan) IMapSelectPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapSelectPlan) PlanKey(com.hazelcast.sql.impl.optimizer.PlanKey) SinkMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.SinkMapPhysicalRel) Permission(java.security.Permission) SqlCreateJob(com.hazelcast.jet.sql.impl.parse.SqlCreateJob) DeleteByKeyMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.DeleteByKeyMapPhysicalRel) SqlDropView(com.hazelcast.jet.sql.impl.parse.SqlDropView) PhysicalRules(com.hazelcast.jet.sql.impl.opt.physical.PhysicalRules) SqlColumnMetadata(com.hazelcast.sql.SqlColumnMetadata) IMapSinkPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapSinkPlan) SqlConnectorCache(com.hazelcast.jet.sql.impl.connector.SqlConnectorCache) RelOptTable(org.apache.calcite.plan.RelOptTable) ArrayList(java.util.ArrayList) LogicalRel(com.hazelcast.jet.sql.impl.opt.logical.LogicalRel) DropIndexPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DropIndexPlan) IMapInsertPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapInsertPlan) SqlDropJob(com.hazelcast.jet.sql.impl.parse.SqlDropJob) ActionConstants(com.hazelcast.security.permission.ActionConstants) Nullable(javax.annotation.Nullable) SqlCreateMapping(com.hazelcast.jet.sql.impl.parse.SqlCreateMapping) HazelcastRelMetadataQuery(com.hazelcast.jet.sql.impl.opt.metadata.HazelcastRelMetadataQuery) DropSnapshotPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DropSnapshotPlan) Aggregate(org.apache.calcite.rel.core.Aggregate) ShowStatementPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.ShowStatementPlan) ExplainStatementPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.ExplainStatementPlan) SqlCreateView(com.hazelcast.jet.sql.impl.parse.SqlCreateView) MetadataResolver(com.hazelcast.jet.sql.impl.connector.map.MetadataResolver) Conventions(com.hazelcast.jet.sql.impl.opt.Conventions) Convention(org.apache.calcite.plan.Convention) QueryConvertResult(com.hazelcast.jet.sql.impl.parse.QueryConvertResult) LogicalRules(com.hazelcast.jet.sql.impl.opt.logical.LogicalRules) RelShuttleImpl(org.apache.calcite.rel.RelShuttleImpl) CreateIndexPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateIndexPlan) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) SqlNode(org.apache.calcite.sql.SqlNode) SqlExplainStatement(com.hazelcast.jet.sql.impl.parse.SqlExplainStatement) ViewTable(com.hazelcast.jet.sql.impl.connector.virtual.ViewTable) AlterJobPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.AlterJobPlan) QueryResultRegistry(com.hazelcast.sql.impl.state.QueryResultRegistry) PostgresqlSqlDialect(org.apache.calcite.sql.dialect.PostgresqlSqlDialect) Objects(java.util.Objects) TableResolver(com.hazelcast.sql.impl.schema.TableResolver) List(java.util.List) SqlDropIndex(com.hazelcast.jet.sql.impl.parse.SqlDropIndex) DropJobPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DropJobPlan) MemberSelectors(com.hazelcast.cluster.memberselector.MemberSelectors) DmlPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DmlPlan) SqlDropMapping(com.hazelcast.jet.sql.impl.parse.SqlDropMapping) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) QueryParseResult(com.hazelcast.jet.sql.impl.parse.QueryParseResult) VolcanoPlanner(org.apache.calcite.plan.volcano.VolcanoPlanner) SqlString(org.apache.calcite.sql.util.SqlString) TablesStorage(com.hazelcast.jet.sql.impl.schema.TablesStorage) MapPermission(com.hazelcast.security.permission.MapPermission) Project(org.apache.calcite.rel.core.Project) TableScan(org.apache.calcite.rel.core.TableScan) WatermarkedFields(com.hazelcast.jet.sql.impl.opt.metadata.WatermarkedFields) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) SqlShowStatement(com.hazelcast.jet.sql.impl.parse.SqlShowStatement) RelOptUtil(org.apache.calcite.plan.RelOptUtil) ILogger(com.hazelcast.logging.ILogger) IMapDeletePlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.IMapDeletePlan) SqlCreateSnapshot(com.hazelcast.jet.sql.impl.parse.SqlCreateSnapshot) QueryException(com.hazelcast.sql.impl.QueryException) SqlPlan(com.hazelcast.sql.impl.optimizer.SqlPlan) SqlDropSnapshot(com.hazelcast.jet.sql.impl.parse.SqlDropSnapshot) SqlAlterJob(com.hazelcast.jet.sql.impl.parse.SqlAlterJob) NodeEngine(com.hazelcast.spi.impl.NodeEngine) CreateViewPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateViewPlan) TableResolverImpl(com.hazelcast.jet.sql.impl.schema.TableResolverImpl) OptUtils(com.hazelcast.jet.sql.impl.opt.OptUtils) InsertMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.InsertMapPhysicalRel) RelNode(org.apache.calcite.rel.RelNode) CreateSnapshotPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateSnapshotPlan) IMapResolver(com.hazelcast.sql.impl.schema.IMapResolver) Mapping(com.hazelcast.sql.impl.schema.Mapping) Collectors.toList(java.util.stream.Collectors.toList) MappingField(com.hazelcast.sql.impl.schema.MappingField) UpdateByKeyMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.UpdateByKeyMapPhysicalRel) PhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.PhysicalRel) SqlCreateMapping(com.hazelcast.jet.sql.impl.parse.SqlCreateMapping) SqlDropMapping(com.hazelcast.jet.sql.impl.parse.SqlDropMapping) Mapping(com.hazelcast.sql.impl.schema.Mapping) CreateMappingPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateMappingPlan) MappingField(com.hazelcast.sql.impl.schema.MappingField)

Aggregations

MappingField (com.hazelcast.sql.impl.schema.MappingField)52 Test (org.junit.Test)23 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)19 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)18 ArrayList (java.util.ArrayList)14 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)10 Mapping (com.hazelcast.sql.impl.schema.Mapping)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Parameters (junitparams.Parameters)8 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)7 TableField (com.hazelcast.sql.impl.schema.TableField)7 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)7 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)6 LinkedHashMap (java.util.LinkedHashMap)6 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)4 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)3 QueryException (com.hazelcast.sql.impl.QueryException)3 SerializationConfig (com.hazelcast.config.SerializationConfig)2 View (com.hazelcast.sql.impl.schema.view.View)2