use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.
the class SqlCreateIndexTest method checkPlan.
private void checkPlan(boolean withIndex, boolean sorted, String sql, String mapName) {
List<QueryDataType> parameterTypes = asList(QueryDataType.INT, QueryDataType.INT);
List<TableField> mapTableFields = asList(new MapTableField("__key", QueryDataType.INT, false, QueryPath.KEY_PATH), new MapTableField("this", QueryDataType.INT, false, QueryPath.VALUE_PATH));
HazelcastTable table = partitionedTable(mapName, mapTableFields, getPartitionedMapIndexes(mapContainer(map), mapTableFields), map.size());
assertThat(table.getProjects().size()).isEqualTo(2);
OptimizerTestSupport.Result optimizationResult = optimizePhysical(sql, parameterTypes, table);
if (sorted) {
if (withIndex) {
assertPlan(optimizationResult.getPhysical(), plan(planRow(0, IndexScanMapPhysicalRel.class)));
} else {
assertPlan(optimizationResult.getPhysical(), plan(planRow(0, SortPhysicalRel.class), planRow(1, FullScanPhysicalRel.class)));
}
} else {
assertPlan(optimizationResult.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
assertPlan(optimizationResult.getPhysical(), plan(planRow(0, withIndex ? IndexScanMapPhysicalRel.class : FullScanPhysicalRel.class)));
}
}
use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.
the class SqlIndexAbstractTest method checkPlan.
private void checkPlan(boolean withIndex, String sql) {
List<QueryDataType> parameterTypes = asList(QueryDataType.INT, f1.getFieldConverterType(), f2.getFieldConverterType());
List<TableField> mapTableFields = asList(new MapTableField("__key", QueryDataType.INT, false, QueryPath.KEY_PATH), new MapTableField("field1", f1.getFieldConverterType(), false, new QueryPath("field1", false)), new MapTableField("field2", f2.getFieldConverterType(), false, new QueryPath("field2", false)));
HazelcastTable table = partitionedTable(mapName, mapTableFields, getPartitionedMapIndexes(mapContainer(map), mapTableFields), map.size());
OptimizerTestSupport.Result optimizationResult = optimizePhysical(sql, parameterTypes, table);
assertPlan(optimizationResult.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
assertPlan(optimizationResult.getPhysical(), plan(planRow(0, withIndex ? IndexScanMapPhysicalRel.class : FullScanPhysicalRel.class)));
}
use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.
the class SqlIndexCastTest method checkIndexUsage.
private void checkIndexUsage(SqlStatement statement, ExpressionType<?> field, boolean expectedIndexUsage) {
List<QueryDataType> parameterTypes = asList(QueryDataType.INT, field.getFieldConverterType());
List<TableField> mapTableFields = asList(new MapTableField("__key", QueryDataType.INT, false, QueryPath.KEY_PATH), new MapTableField("field1", field.getFieldConverterType(), false, new QueryPath("field1", false)));
HazelcastTable table = partitionedTable(MAP_NAME, mapTableFields, getPartitionedMapIndexes(mapContainer(instance().getMap(MAP_NAME)), mapTableFields), 1);
Result optimizationResult = optimizePhysical(statement.getSql(), parameterTypes, table);
assertPlan(optimizationResult.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
assertPlan(optimizationResult.getPhysical(), plan(planRow(0, expectedIndexUsage ? IndexScanMapPhysicalRel.class : FullScanPhysicalRel.class)));
}
use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.
the class TestAbstractSqlConnector 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) {
String[] names = options.get(OPTION_NAMES).split(DELIMITER);
String[] types = options.get(OPTION_TYPES).split(DELIMITER);
assert names.length == types.length;
List<TableField> fields = new ArrayList<>(names.length);
for (int i = 0; i < names.length; i++) {
fields.add(new TableField(names[i], resolveTypeForTypeFamily(QueryDataTypeFamily.valueOf(types[i])), false));
}
List<Object[]> rows = new ArrayList<>();
String[] rowsSerialized = options.get(OPTION_VALUES).split(VALUES_DELIMITER);
for (String rowSerialized : rowsSerialized) {
if (rowSerialized.isEmpty()) {
continue;
}
String[] values = rowSerialized.split(DELIMITER);
assert values.length == fields.size();
Object[] row = new Object[values.length];
for (int i = 0; i < values.length; i++) {
String value = values[i];
if (NULL.equals(value)) {
row[i] = null;
} else {
row[i] = fields.get(i).getType().convert(values[i]);
}
}
rows.add(row);
}
boolean streaming = Boolean.parseBoolean(options.get(OPTION_STREAMING));
return new TestTable(this, schemaName, mappingName, fields, rows, streaming);
}
use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.
the class PartitionedMapPlanObjectKeyTest method test_partitioned.
@Test
public void test_partitioned() {
String schema1 = "schema1";
String schema2 = "schema2";
String tableName1 = "table1";
String tableName2 = "table2";
String mapName1 = "map1";
String mapName2 = "map2";
List<TableField> fields1 = singletonList(new MapTableField("field1", QueryDataType.INT, true, QueryPath.KEY_PATH));
List<TableField> fields2 = singletonList(new MapTableField("field2", QueryDataType.INT, true, QueryPath.KEY_PATH));
Set<String> conflictingSchemas1 = Collections.singleton("schema1");
Set<String> conflictingSchemas2 = Collections.singleton("schema2");
QueryTargetDescriptor keyDescriptor1 = GenericQueryTargetDescriptor.DEFAULT;
QueryTargetDescriptor keyDescriptor2 = new TestTargetDescriptor();
QueryTargetDescriptor valueDescriptor1 = GenericQueryTargetDescriptor.DEFAULT;
QueryTargetDescriptor valueDescriptor2 = new TestTargetDescriptor();
Object keyJetMetadata1 = new Object();
Object valueJetMetadata1 = new Object();
Object keyJetMetadata2 = new Object();
Object valueJetMetadata2 = new Object();
List<MapTableIndex> indexes1 = singletonList(new MapTableIndex("idx", IndexType.SORTED, 0, emptyList(), emptyList()));
List<MapTableIndex> indexes2 = singletonList(new MapTableIndex("idx", IndexType.HASH, 0, emptyList(), emptyList()));
boolean hd1 = false;
boolean hd2 = true;
PartitionedMapPlanObjectKey objectId = new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1);
checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), true);
checkEquals(objectId, new PartitionedMapPlanObjectKey(schema2, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
checkEquals(objectId, new PartitionedMapPlanObjectKey(schema2, tableName2, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName2, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields2, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas2, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor2, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor2, keyJetMetadata1, valueJetMetadata1, indexes1, hd1), false);
checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor2, keyJetMetadata2, valueJetMetadata1, indexes1, hd1), false);
checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor2, keyJetMetadata1, valueJetMetadata2, indexes1, hd1), false);
checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes2, hd1), false);
checkEquals(objectId, new PartitionedMapPlanObjectKey(schema1, tableName1, mapName1, fields1, conflictingSchemas1, keyDescriptor1, valueDescriptor1, keyJetMetadata1, valueJetMetadata1, indexes1, hd2), false);
}
Aggregations