Search in sources :

Example 11 with Mapping

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\"}" });
}
Also used : Mapping(com.hazelcast.sql.impl.schema.Mapping) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with Mapping

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

Example 13 with Mapping

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

Example 14 with Mapping

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)));
}
Also used : SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Collections.emptyMap(java.util.Collections.emptyMap) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) Collections.emptyList(java.util.Collections.emptyList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Accessors(com.hazelcast.test.Accessors) Mapping(com.hazelcast.sql.impl.schema.Mapping) View(com.hazelcast.sql.impl.schema.view.View) Before(org.junit.Before) Mapping(com.hazelcast.sql.impl.schema.Mapping) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with Mapping

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);
}
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

Mapping (com.hazelcast.sql.impl.schema.Mapping)20 MappingField (com.hazelcast.sql.impl.schema.MappingField)11 Test (org.junit.Test)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 View (com.hazelcast.sql.impl.schema.view.View)6 ArrayList (java.util.ArrayList)4 NodeEngine (com.hazelcast.spi.impl.NodeEngine)3 MemberSelectors (com.hazelcast.cluster.memberselector.MemberSelectors)2 EntryEvent (com.hazelcast.core.EntryEvent)2 CreateMappingPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateMappingPlan)2 SqlCreateMapping (com.hazelcast.jet.sql.impl.parse.SqlCreateMapping)2 ILogger (com.hazelcast.logging.ILogger)2 QueryException (com.hazelcast.sql.impl.QueryException)2 List (java.util.List)2 Objects (java.util.Objects)2 Collectors.toList (java.util.stream.Collectors.toList)2 Nullable (javax.annotation.Nullable)2 Address (com.hazelcast.cluster.Address)1 Member (com.hazelcast.cluster.Member)1