Search in sources :

Example 1 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class MappingColumnsTable method rows.

@Override
protected List<Object[]> rows() {
    List<Object[]> rows = new ArrayList<>(mappings.size());
    for (Mapping mapping : mappings) {
        List<MappingField> fields = mapping.fields();
        for (int i = 0; i < fields.size(); i++) {
            MappingField field = fields.get(i);
            Object[] row = new Object[] { catalog(), schema, mapping.name(), field.name(), field.externalName(), i + 1, String.valueOf(true), field.type().getTypeFamily().name() };
            rows.add(row);
        }
    }
    for (View view : views) {
        for (int i = 0; i < view.viewColumnNames().size(); i++) {
            Object[] row = new Object[] { catalog(), schema, view.name(), view.viewColumnNames().get(i), null, i + 1, String.valueOf(true), view.viewColumnTypes().get(i).getTypeFamily().name() };
            rows.add(row);
        }
    }
    return rows;
}
Also used : ArrayList(java.util.ArrayList) Mapping(com.hazelcast.sql.impl.schema.Mapping) MappingField(com.hazelcast.sql.impl.schema.MappingField) View(com.hazelcast.sql.impl.schema.view.View)

Example 2 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class TableResolverImpl method createMapping.

// region mapping
public void createMapping(Mapping mapping, boolean replace, boolean ifNotExists) {
    Mapping resolved = resolveMapping(mapping);
    String name = resolved.name();
    if (ifNotExists) {
        tableStorage.putIfAbsent(name, resolved);
    } else if (replace) {
        tableStorage.put(name, resolved);
        listeners.forEach(TableListener::onTableChanged);
    } else if (!tableStorage.putIfAbsent(name, resolved)) {
        throw QueryException.error("Mapping or view already exists: " + name);
    }
}
Also used : Mapping(com.hazelcast.sql.impl.schema.Mapping)

Example 3 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class TableResolverImpl method getTables.

@Nonnull
@Override
public List<Table> getTables() {
    Collection<Object> objects = tableStorage.allObjects();
    List<Table> tables = new ArrayList<>(objects.size() + 3);
    for (Object o : objects) {
        if (o instanceof Mapping) {
            tables.add(toTable((Mapping) o));
        } else if (o instanceof View) {
            tables.add(toTable((View) o));
        } else {
            throw new RuntimeException("Unexpected: " + o);
        }
    }
    Collection<Mapping> mappings = objects.stream().filter(o -> o instanceof Mapping).map(m -> (Mapping) m).collect(Collectors.toList());
    Collection<View> views = objects.stream().filter(o -> o instanceof View).map(v -> (View) v).collect(Collectors.toList());
    tables.add(new TablesTable(CATALOG, SCHEMA_NAME_INFORMATION_SCHEMA, SCHEMA_NAME_PUBLIC, mappings, views));
    tables.add(new MappingsTable(CATALOG, SCHEMA_NAME_INFORMATION_SCHEMA, SCHEMA_NAME_PUBLIC, mappings));
    tables.add(new MappingColumnsTable(CATALOG, SCHEMA_NAME_INFORMATION_SCHEMA, SCHEMA_NAME_PUBLIC, mappings, views));
    tables.add(new ViewsTable(CATALOG, SCHEMA_NAME_INFORMATION_SCHEMA, SCHEMA_NAME_PUBLIC, views));
    return tables;
}
Also used : SqlConnectorCache(com.hazelcast.jet.sql.impl.connector.SqlConnectorCache) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) LinkedHashMap(java.util.LinkedHashMap) ViewsTable(com.hazelcast.jet.sql.impl.connector.infoschema.ViewsTable) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ConstantTableStatistics(com.hazelcast.sql.impl.schema.ConstantTableStatistics) SqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnector) MappingsTable(com.hazelcast.jet.sql.impl.connector.infoschema.MappingsTable) View(com.hazelcast.sql.impl.schema.view.View) Nonnull(javax.annotation.Nonnull) QueryException(com.hazelcast.sql.impl.QueryException) EntryEvent(com.hazelcast.core.EntryEvent) ViewTable(com.hazelcast.jet.sql.impl.connector.virtual.ViewTable) NodeEngine(com.hazelcast.spi.impl.NodeEngine) Collection(java.util.Collection) MappingColumnsTable(com.hazelcast.jet.sql.impl.connector.infoschema.MappingColumnsTable) Collectors(java.util.stream.Collectors) Mapping(com.hazelcast.sql.impl.schema.Mapping) TableField(com.hazelcast.sql.impl.schema.TableField) TablesTable(com.hazelcast.jet.sql.impl.connector.infoschema.TablesTable) TableResolver(com.hazelcast.sql.impl.schema.TableResolver) List(java.util.List) CATALOG(com.hazelcast.sql.impl.QueryUtils.CATALOG) MappingField(com.hazelcast.sql.impl.schema.MappingField) Table(com.hazelcast.sql.impl.schema.Table) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ViewsTable(com.hazelcast.jet.sql.impl.connector.infoschema.ViewsTable) MappingsTable(com.hazelcast.jet.sql.impl.connector.infoschema.MappingsTable) ViewTable(com.hazelcast.jet.sql.impl.connector.virtual.ViewTable) MappingColumnsTable(com.hazelcast.jet.sql.impl.connector.infoschema.MappingColumnsTable) TablesTable(com.hazelcast.jet.sql.impl.connector.infoschema.TablesTable) Table(com.hazelcast.sql.impl.schema.Table) ViewsTable(com.hazelcast.jet.sql.impl.connector.infoschema.ViewsTable) TablesTable(com.hazelcast.jet.sql.impl.connector.infoschema.TablesTable) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Mapping(com.hazelcast.sql.impl.schema.Mapping) View(com.hazelcast.sql.impl.schema.view.View) MappingsTable(com.hazelcast.jet.sql.impl.connector.infoschema.MappingsTable) MappingColumnsTable(com.hazelcast.jet.sql.impl.connector.infoschema.MappingColumnsTable) Nonnull(javax.annotation.Nonnull)

Example 4 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class SqlDataSerializerHook method createFactory.

@SuppressWarnings("unchecked")
@Override
public DataSerializableFactory createFactory() {
    ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[LEN];
    constructors[QUERY_DATA_TYPE] = arg -> new QueryDataType();
    constructors[QUERY_ID] = arg -> new QueryId();
    constructors[ROW_HEAP] = arg -> new HeapRow();
    constructors[ROW_EMPTY] = arg -> EmptyRow.INSTANCE;
    constructors[LAZY_TARGET] = arg -> new LazyTarget();
    constructors[INDEX_FILTER_VALUE] = arg -> new IndexFilterValue();
    constructors[INDEX_FILTER_EQUALS] = arg -> new IndexEqualsFilter();
    constructors[INDEX_FILTER_RANGE] = arg -> new IndexRangeFilter();
    constructors[INDEX_FILTER_IN] = arg -> new IndexInFilter();
    constructors[EXPRESSION_COLUMN] = arg -> new ColumnExpression<>();
    constructors[EXPRESSION_IS_NULL] = arg -> new IsNullPredicate();
    constructors[TARGET_DESCRIPTOR_GENERIC] = arg -> GenericQueryTargetDescriptor.DEFAULT;
    constructors[QUERY_PATH] = arg -> new QueryPath();
    constructors[EXPRESSION_CONSTANT] = arg -> new ConstantExpression<>();
    constructors[EXPRESSION_PARAMETER] = arg -> new ParameterExpression<>();
    constructors[EXPRESSION_CAST] = arg -> new CastExpression<>();
    constructors[EXPRESSION_DIVIDE] = arg -> new DivideFunction<>();
    constructors[EXPRESSION_MINUS] = arg -> new MinusFunction<>();
    constructors[EXPRESSION_MULTIPLY] = arg -> new MultiplyFunction<>();
    constructors[EXPRESSION_PLUS] = arg -> new PlusFunction<>();
    constructors[EXPRESSION_UNARY_MINUS] = arg -> new UnaryMinusFunction<>();
    constructors[EXPRESSION_AND] = arg -> new AndPredicate();
    constructors[EXPRESSION_OR] = arg -> new OrPredicate();
    constructors[EXPRESSION_NOT] = arg -> new NotPredicate();
    constructors[EXPRESSION_COMPARISON] = arg -> new ComparisonPredicate();
    constructors[EXPRESSION_IS_TRUE] = arg -> new IsTruePredicate();
    constructors[EXPRESSION_IS_NOT_TRUE] = arg -> new IsNotTruePredicate();
    constructors[EXPRESSION_IS_FALSE] = arg -> new IsFalsePredicate();
    constructors[EXPRESSION_IS_NOT_FALSE] = arg -> new IsNotFalsePredicate();
    constructors[EXPRESSION_IS_NOT_NULL] = arg -> new IsNotNullPredicate();
    constructors[EXPRESSION_ABS] = arg -> new AbsFunction<>();
    constructors[EXPRESSION_SIGN] = arg -> new SignFunction<>();
    constructors[EXPRESSION_RAND] = arg -> new RandFunction();
    constructors[EXPRESSION_DOUBLE] = arg -> new DoubleFunction();
    constructors[EXPRESSION_FLOOR_CEIL] = arg -> new FloorCeilFunction<>();
    constructors[EXPRESSION_ROUND_TRUNCATE] = arg -> new RoundTruncateFunction<>();
    constructors[INTERVAL_YEAR_MONTH] = arg -> new SqlYearMonthInterval();
    constructors[INTERVAL_DAY_SECOND] = arg -> new SqlDaySecondInterval();
    constructors[EXPRESSION_ASCII] = arg -> new AsciiFunction();
    constructors[EXPRESSION_CHAR_LENGTH] = arg -> new CharLengthFunction();
    constructors[EXPRESSION_INITCAP] = arg -> new InitcapFunction();
    constructors[EXPRESSION_LOWER] = arg -> new LowerFunction();
    constructors[EXPRESSION_UPPER] = arg -> new UpperFunction();
    constructors[EXPRESSION_CONCAT] = arg -> new ConcatFunction();
    constructors[EXPRESSION_LIKE] = arg -> new LikeFunction();
    constructors[EXPRESSION_SUBSTRING] = arg -> new SubstringFunction();
    constructors[EXPRESSION_TRIM] = arg -> new TrimFunction();
    constructors[EXPRESSION_REPLACE] = arg -> new ReplaceFunction();
    constructors[EXPRESSION_POSITION] = arg -> new PositionFunction();
    constructors[EXPRESSION_REMAINDER] = arg -> new RemainderFunction<>();
    constructors[EXPRESSION_CONCAT_WS] = arg -> new ConcatWSFunction();
    constructors[EXPRESSION_CASE] = arg -> new CaseExpression<>();
    constructors[EXPRESSION_EXTRACT] = arg -> new ExtractFunction();
    constructors[EXPRESSION_DOUBLE_DOUBLE] = arg -> new DoubleBiFunction();
    constructors[EXPRESSION_TO_TIMESTAMP_TZ] = arg -> new ToTimestampTzFunction();
    constructors[EXPRESSION_TO_EPOCH_MILLIS] = arg -> new ToEpochMillisFunction();
    constructors[MAPPING] = arg -> new Mapping();
    constructors[MAPPING_FIELD] = arg -> new MappingField();
    constructors[EXPRESSION_SEARCHABLE] = arg -> new SearchableExpression<>();
    constructors[EXPRESSION_SEARCH] = arg -> new SearchPredicate();
    constructors[VIEW] = arg -> new View();
    return new ArrayDataSerializableFactory(constructors);
}
Also used : ConcatWSFunction(com.hazelcast.sql.impl.expression.string.ConcatWSFunction) LowerFunction(com.hazelcast.sql.impl.expression.string.LowerFunction) IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) IsFalsePredicate(com.hazelcast.sql.impl.expression.predicate.IsFalsePredicate) Mapping(com.hazelcast.sql.impl.schema.Mapping) HeapRow(com.hazelcast.sql.impl.row.HeapRow) SearchPredicate(com.hazelcast.sql.impl.expression.predicate.SearchPredicate) PositionFunction(com.hazelcast.sql.impl.expression.string.PositionFunction) ConcatFunction(com.hazelcast.sql.impl.expression.string.ConcatFunction) IsNotTruePredicate(com.hazelcast.sql.impl.expression.predicate.IsNotTruePredicate) OrPredicate(com.hazelcast.sql.impl.expression.predicate.OrPredicate) ExtractFunction(com.hazelcast.sql.impl.expression.datetime.ExtractFunction) IndexFilterValue(com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue) IsNullPredicate(com.hazelcast.sql.impl.expression.predicate.IsNullPredicate) UpperFunction(com.hazelcast.sql.impl.expression.string.UpperFunction) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) MappingField(com.hazelcast.sql.impl.schema.MappingField) DoubleBiFunction(com.hazelcast.sql.impl.expression.math.DoubleBiFunction) TrimFunction(com.hazelcast.sql.impl.expression.string.TrimFunction) ToEpochMillisFunction(com.hazelcast.sql.impl.expression.datetime.ToEpochMillisFunction) RandFunction(com.hazelcast.sql.impl.expression.math.RandFunction) CharLengthFunction(com.hazelcast.sql.impl.expression.string.CharLengthFunction) SqlYearMonthInterval(com.hazelcast.sql.impl.type.SqlYearMonthInterval) LikeFunction(com.hazelcast.sql.impl.expression.string.LikeFunction) ReplaceFunction(com.hazelcast.sql.impl.expression.string.ReplaceFunction) IsNotFalsePredicate(com.hazelcast.sql.impl.expression.predicate.IsNotFalsePredicate) ComparisonPredicate(com.hazelcast.sql.impl.expression.predicate.ComparisonPredicate) SubstringFunction(com.hazelcast.sql.impl.expression.string.SubstringFunction) QueryPath(com.hazelcast.sql.impl.extract.QueryPath) IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) ToTimestampTzFunction(com.hazelcast.sql.impl.expression.datetime.ToTimestampTzFunction) InitcapFunction(com.hazelcast.sql.impl.expression.string.InitcapFunction) AndPredicate(com.hazelcast.sql.impl.expression.predicate.AndPredicate) IndexInFilter(com.hazelcast.sql.impl.exec.scan.index.IndexInFilter) SqlDaySecondInterval(com.hazelcast.sql.impl.type.SqlDaySecondInterval) NotPredicate(com.hazelcast.sql.impl.expression.predicate.NotPredicate) View(com.hazelcast.sql.impl.schema.view.View) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction) IsNotNullPredicate(com.hazelcast.sql.impl.expression.predicate.IsNotNullPredicate) DoubleFunction(com.hazelcast.sql.impl.expression.math.DoubleFunction) AsciiFunction(com.hazelcast.sql.impl.expression.string.AsciiFunction) IsTruePredicate(com.hazelcast.sql.impl.expression.predicate.IsTruePredicate) ArrayDataSerializableFactory(com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)

Example 5 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class PlanExecutorTest method test_createMappingExecution.

@Test
@Parameters({ "true, false", "false, true" })
public void test_createMappingExecution(boolean replace, boolean ifNotExists) {
    // given
    Mapping mapping = mapping();
    CreateMappingPlan plan = new CreateMappingPlan(planKey(), mapping, replace, ifNotExists, planExecutor);
    // when
    SqlResult result = planExecutor.execute(plan);
    // then
    assertThat(result.updateCount()).isEqualTo(0);
    verify(catalog).createMapping(mapping, replace, ifNotExists);
}
Also used : SqlResult(com.hazelcast.sql.SqlResult) Mapping(com.hazelcast.sql.impl.schema.Mapping) CreateMappingPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateMappingPlan) Parameters(junitparams.Parameters) Test(org.junit.Test)

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