use of com.hazelcast.sql.impl.extract.QueryPath in project hazelcast by hazelcast.
the class KvMetadataJavaResolver method resolvePrimitiveMetadata.
private KvMetadata resolvePrimitiveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<QueryPath, MappingField> fieldsByPath, QueryDataType type) {
List<TableField> fields = new ArrayList<>();
QueryPath path = isKey ? QueryPath.KEY_PATH : QueryPath.VALUE_PATH;
MappingField field = fieldsByPath.get(path);
if (field != null) {
fields.add(new MapTableField(field.name(), field.type(), false, path));
}
maybeAddDefaultField(isKey, resolvedFields, fields, type);
return new KvMetadata(fields, GenericQueryTargetDescriptor.DEFAULT, PrimitiveUpsertTargetDescriptor.INSTANCE);
}
use of com.hazelcast.sql.impl.extract.QueryPath in project hazelcast by hazelcast.
the class KvMetadataJsonResolverTest method when_noKeyOrThisPrefixInExternalName_then_usesValue.
@Test
@Parameters({ "true", "false" })
public void when_noKeyOrThisPrefixInExternalName_then_usesValue(boolean key) {
KvMetadata metadata = INSTANCE.resolveMetadata(key, singletonList(field("field", QueryDataType.INT, "extField")), emptyMap(), null);
assertThat(metadata.getFields()).containsExactly(key ? new MapTableField[] { new MapTableField("__key", QueryDataType.OBJECT, true, QueryPath.KEY_PATH) } : new MapTableField[] { new MapTableField("field", QueryDataType.INT, false, new QueryPath("extField", false)), new MapTableField("this", QueryDataType.OBJECT, true, QueryPath.VALUE_PATH) });
}
use of com.hazelcast.sql.impl.extract.QueryPath 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);
}
use of com.hazelcast.sql.impl.extract.QueryPath in project hazelcast by hazelcast.
the class MapScanRow method create.
public static MapScanRow create(QueryTargetDescriptor keyDescriptor, QueryTargetDescriptor valueDescriptor, List<QueryPath> fieldPaths, List<QueryDataType> fieldTypes, Extractors extractors, InternalSerializationService serializationService) {
QueryTarget keyTarget = keyDescriptor.create(serializationService, extractors, true);
QueryTarget valueTarget = valueDescriptor.create(serializationService, extractors, false);
QueryExtractor[] fieldExtractors = new QueryExtractor[fieldPaths.size()];
for (int i = 0; i < fieldPaths.size(); i++) {
QueryPath fieldPath = fieldPaths.get(i);
QueryDataType fieldType = fieldTypes.get(i);
fieldExtractors[i] = createExtractor(keyTarget, valueTarget, fieldPath, fieldType);
}
return new MapScanRow(keyTarget, valueTarget, fieldExtractors);
}
use of com.hazelcast.sql.impl.extract.QueryPath in project hazelcast by hazelcast.
the class MapTableUtils method getPartitionedMapIndexes.
public static List<MapTableIndex> getPartitionedMapIndexes(MapContainer mapContainer, List<TableField> fields) {
Map<QueryPath, Integer> pathToOrdinalMap = mapPathsToOrdinals(fields);
if (mapContainer.getIndexes() == null) {
return Collections.emptyList();
}
InternalIndex[] indexes = mapContainer.getIndexes().getIndexes();
if (indexes == null || indexes.length == 0) {
return Collections.emptyList();
}
List<MapTableIndex> res = new ArrayList<>(indexes.length);
for (Index index : indexes) {
IndexConfig indexConfig = index.getConfig();
List<QueryDataType> resolvedFieldConverterTypes = indexConverterToSqlTypes(index.getConverter());
List<String> indexAttributes = indexConfig.getAttributes();
List<Integer> indexFieldOrdinals = new ArrayList<>(indexAttributes.size());
List<QueryDataType> indexFieldConverterTypes = new ArrayList<>(indexAttributes.size());
String[] components = index.getComponents();
for (int i = 0; i < indexAttributes.size(); i++) {
String attribute = indexAttributes.get(i);
QueryPath attributePath = QueryPath.create(attribute);
Integer ordinal = pathToOrdinalMap.get(attributePath);
if (ordinal == null) {
// No mapping for the field. Stop.
break;
}
if (i >= resolvedFieldConverterTypes.size()) {
// No more resolved converters. Stop.
break;
}
QueryDataType fieldType = fields.get(ordinal).getType();
QueryDataType converterType = resolvedFieldConverterTypes.get(i);
if (!isCompatibleForIndexRequest(fieldType, converterType)) {
// Field and converter types are not compatible (e.g. INT vs VARCHAR).
break;
}
indexFieldOrdinals.add(ordinal);
indexFieldConverterTypes.add(converterType);
}
MapTableIndex index0 = new MapTableIndex(indexConfig.getName(), indexConfig.getType(), components.length, indexFieldOrdinals, indexFieldConverterTypes);
res.add(index0);
}
return res;
}
Aggregations