use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.
the class IMapSqlConnector method createTable.
@Nonnull
@Override
public Table createTable(@Nonnull NodeEngine nodeEngine, @Nonnull String schemaName, @Nonnull String mappingName, @Nonnull String externalName, @Nonnull Map<String, String> options, @Nonnull List<MappingField> resolvedFields) {
InternalSerializationService ss = (InternalSerializationService) nodeEngine.getSerializationService();
KvMetadata keyMetadata = METADATA_RESOLVERS.resolveMetadata(true, resolvedFields, options, ss);
KvMetadata valueMetadata = METADATA_RESOLVERS.resolveMetadata(false, resolvedFields, options, ss);
List<TableField> fields = concat(keyMetadata.getFields().stream(), valueMetadata.getFields().stream()).collect(toList());
MapService service = nodeEngine.getService(MapService.SERVICE_NAME);
MapServiceContext context = service.getMapServiceContext();
MapContainer container = context.getExistingMapContainer(externalName);
long estimatedRowCount = estimatePartitionedMapRowCount(nodeEngine, context, externalName);
boolean hd = container != null && container.getMapConfig().getInMemoryFormat() == InMemoryFormat.NATIVE;
List<MapTableIndex> indexes = container != null ? MapTableUtils.getPartitionedMapIndexes(container, fields) : emptyList();
return new PartitionedMapTable(schemaName, mappingName, externalName, fields, new ConstantTableStatistics(estimatedRowCount), keyMetadata.getQueryTargetDescriptor(), valueMetadata.getQueryTargetDescriptor(), keyMetadata.getUpsertTargetDescriptor(), valueMetadata.getUpsertTargetDescriptor(), indexes, hd);
}
use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.
the class MetadataCompactResolver method resolveMetadata.
@Override
public KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<String, String> options, InternalSerializationService serializationService) {
Map<QueryPath, MappingField> fieldsByPath = extractFields(resolvedFields, isKey);
String typeNameProperty = isKey ? OPTION_KEY_COMPACT_TYPE_NAME : OPTION_VALUE_COMPACT_TYPE_NAME;
String typeName = options.get(typeNameProperty);
List<TableField> fields = new ArrayList<>(fieldsByPath.size());
for (Entry<QueryPath, MappingField> entry : fieldsByPath.entrySet()) {
QueryPath path = entry.getKey();
QueryDataType type = entry.getValue().type();
String name = entry.getValue().name();
fields.add(new MapTableField(name, type, false, path));
}
maybeAddDefaultField(isKey, resolvedFields, fields, QueryDataType.OBJECT);
Schema schema = resolveSchema(typeName, fieldsByPath);
return new KvMetadata(fields, GenericQueryTargetDescriptor.DEFAULT, new CompactUpsertTargetDescriptor(schema));
}
use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.
the class KafkaSqlConnector method createTable.
@Nonnull
@Override
public Table createTable(@Nonnull NodeEngine nodeEngine, @Nonnull String schemaName, @Nonnull String mappingName, @Nonnull String externalName, @Nonnull Map<String, String> options, @Nonnull List<MappingField> resolvedFields) {
KvMetadata keyMetadata = METADATA_RESOLVERS.resolveMetadata(true, resolvedFields, options, null);
KvMetadata valueMetadata = METADATA_RESOLVERS.resolveMetadata(false, resolvedFields, options, null);
List<TableField> fields = concat(keyMetadata.getFields().stream(), valueMetadata.getFields().stream()).collect(toList());
return new KafkaTable(this, schemaName, mappingName, fields, new ConstantTableStatistics(0), externalName, options, keyMetadata.getQueryTargetDescriptor(), keyMetadata.getUpsertTargetDescriptor(), valueMetadata.getQueryTargetDescriptor(), valueMetadata.getUpsertTargetDescriptor());
}
use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.
the class KvMetadataAvroResolver method resolveMetadata.
@Override
public KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<String, String> options, InternalSerializationService serializationService) {
Map<QueryPath, MappingField> fieldsByPath = extractFields(resolvedFields, isKey);
List<TableField> fields = new ArrayList<>();
for (Entry<QueryPath, MappingField> entry : fieldsByPath.entrySet()) {
QueryPath path = entry.getKey();
QueryDataType type = entry.getValue().type();
String name = entry.getValue().name();
fields.add(new MapTableField(name, type, false, path));
}
maybeAddDefaultField(isKey, resolvedFields, fields, QueryDataType.OBJECT);
return new KvMetadata(fields, AvroQueryTargetDescriptor.INSTANCE, new AvroUpsertTargetDescriptor(schema(fields).toString()));
}
use of com.hazelcast.sql.impl.schema.TableField 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);
}
Aggregations