use of com.hazelcast.sql.impl.type.QueryDataType 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.type.QueryDataType in project hazelcast by hazelcast.
the class HazelcastTypeUtils method canCast.
public static boolean canCast(RelDataType sourceType, RelDataType targetType) {
if (targetType.equals(sourceType)) {
return true;
}
if (sourceType.isStruct() || targetType.isStruct()) {
if (sourceType.getSqlTypeName() != SqlTypeName.ROW) {
throw new IllegalArgumentException("Unexpected source type: " + sourceType);
}
if (targetType.getSqlTypeName() != SqlTypeName.ROW) {
throw new IllegalArgumentException("Unexpected target type: " + targetType);
}
int n = targetType.getFieldCount();
if (sourceType.getFieldCount() != n) {
return false;
}
for (int i = 0; i < n; ++i) {
RelDataTypeField toField = targetType.getFieldList().get(i);
RelDataTypeField fromField = sourceType.getFieldList().get(i);
if (!canCast(toField.getType(), fromField.getType())) {
return false;
}
}
return true;
}
QueryDataType queryFrom = toHazelcastType(sourceType);
QueryDataType queryTo = toHazelcastType(targetType);
return queryFrom.getConverter().canConvertTo(queryTo.getTypeFamily());
}
use of com.hazelcast.sql.impl.type.QueryDataType in project hazelcast by hazelcast.
the class HazelcastTypeUtils method toHazelcastTypeFromSqlTypeName.
public static QueryDataType toHazelcastTypeFromSqlTypeName(SqlTypeName sqlTypeName) {
SqlTypeFamily sqlTypeNameFamily = sqlTypeName.getFamily();
if (sqlTypeNameFamily == SqlTypeFamily.INTERVAL_YEAR_MONTH) {
return QueryDataType.INTERVAL_YEAR_MONTH;
} else if (sqlTypeNameFamily == SqlTypeFamily.INTERVAL_DAY_TIME) {
return QueryDataType.INTERVAL_DAY_SECOND;
}
QueryDataType queryDataType = CALCITE_TO_HZ.get(sqlTypeName);
if (queryDataType == null) {
throw new IllegalArgumentException("Unexpected SQL type: " + sqlTypeName);
}
return queryDataType;
}
use of com.hazelcast.sql.impl.type.QueryDataType 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.type.QueryDataType 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)));
}
Aggregations