org.apache.calcite.rel.type.RelRecordType Java Examples
The following examples show how to use
org.apache.calcite.rel.type.RelRecordType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlTypeFactoryTest.java From calcite with Apache License 2.0 | 6 votes |
/** Test case for * <a href="https://issues.apache.org/jira/browse/CALCITE-2464">[CALCITE-2464] * Allow to set nullability for columns of structured types</a>. */ @Test void createStructTypeWithNullability() { SqlTypeFixture f = new SqlTypeFixture(); RelDataTypeFactory typeFactory = f.typeFactory; List<RelDataTypeField> fields = new ArrayList<>(); RelDataTypeField field0 = new RelDataTypeFieldImpl( "i", 0, typeFactory.createSqlType(SqlTypeName.INTEGER)); RelDataTypeField field1 = new RelDataTypeFieldImpl( "s", 1, typeFactory.createSqlType(SqlTypeName.VARCHAR)); fields.add(field0); fields.add(field1); final RelDataType recordType = new RelRecordType(fields); // nullable false by default final RelDataType copyRecordType = typeFactory.createTypeWithNullability(recordType, true); assertFalse(recordType.isNullable()); assertTrue(copyRecordType.isNullable()); }
Example #2
Source File: JavaTypeFactoryImpl.java From calcite with Apache License 2.0 | 6 votes |
/** Creates a synthetic Java class whose fields have the same names and * relational types. */ private Type createSyntheticType(RelRecordType type) { final String name = "Record" + type.getFieldCount() + "_" + syntheticTypes.size(); final SyntheticRecordType syntheticType = new SyntheticRecordType(type, name); for (final RelDataTypeField recordField : type.getFieldList()) { final Type javaClass = getJavaClass(recordField.getType()); syntheticType.fields.add( new RecordFieldImpl( syntheticType, recordField.getName(), javaClass, recordField.getType().isNullable() && !Primitive.is(javaClass), Modifier.PUBLIC)); } return register(syntheticType); }
Example #3
Source File: PlanExecutor.java From quark with Apache License 2.0 | 6 votes |
private RelDataType getViewRowType() { List<RelDataTypeField> relDataTypeFields = ImmutableList.<RelDataTypeField>of( new RelDataTypeFieldImpl("id", 1, getIntegerJavaType()), new RelDataTypeFieldImpl("name", 2, getStringJavaType()), new RelDataTypeFieldImpl("description", 3, getStringJavaType()), new RelDataTypeFieldImpl("cost", 4, getIntegerJavaType()), new RelDataTypeFieldImpl("query", 5, getStringJavaType()), new RelDataTypeFieldImpl("destination_id", 6, getIntegerJavaType()), new RelDataTypeFieldImpl("schema_name", 7, getStringJavaType()), new RelDataTypeFieldImpl("table_name", 8, getStringJavaType()), new RelDataTypeFieldImpl("ds_set_id", 9, getIntegerJavaType())); return new RelRecordType(relDataTypeFields); }
Example #4
Source File: PlanExecutor.java From quark with Apache License 2.0 | 6 votes |
private RelDataType getDataSourceRowType() throws SQLException { List<RelDataTypeField> relDataTypeFields = ImmutableList.<RelDataTypeField>of( new RelDataTypeFieldImpl("id", 1, getIntegerJavaType()), new RelDataTypeFieldImpl("type", 2, getStringJavaType()), new RelDataTypeFieldImpl("url", 3, getStringJavaType()), new RelDataTypeFieldImpl("name", 4, getStringJavaType()), new RelDataTypeFieldImpl("ds_set_id", 5, getIntegerJavaType()), new RelDataTypeFieldImpl("datasource_type", 6, getStringJavaType()), new RelDataTypeFieldImpl("auth_token", 7, getStringJavaType()), new RelDataTypeFieldImpl("dbtap_id", 8, getIntegerJavaType()), new RelDataTypeFieldImpl("username", 9, getStringJavaType()), new RelDataTypeFieldImpl("password", 10, getStringJavaType())); return new RelRecordType(relDataTypeFields); }
Example #5
Source File: TestAvroRelConversion.java From samza with Apache License 2.0 | 6 votes |
@Test public void testSimpleSchemaConversion() { String streamName = "stream"; SqlSchema sqlSchema = simpleRecordSchemaProvider.getSqlSchema(); RelDataType dataType = relSchemaConverter.convertToRelSchema(sqlSchema); junit.framework.Assert.assertTrue(dataType instanceof RelRecordType); RelRecordType recordType = (RelRecordType) dataType; junit.framework.Assert.assertEquals(recordType.getFieldCount(), SimpleRecord.SCHEMA$.getFields().size()); junit.framework.Assert.assertTrue( recordType.getField("id", true, false).getType().getSqlTypeName() == SqlTypeName.INTEGER); junit.framework.Assert.assertTrue( recordType.getField("name", true, false).getType().getSqlTypeName() == SqlTypeName.VARCHAR); LOG.info("Relational schema " + dataType); }
Example #6
Source File: TestValuesRel.java From dremio-oss with Apache License 2.0 | 6 votes |
@Test public void testNumericValuesRelRowTypeAdjustment() { final int INListLength = 20; // Build RowType & Tuples RelDataTypeField relDataType = new RelDataTypeFieldImpl("ROW_VALUE", 0, new BasicSqlType(RelDataTypeSystemImpl.REL_DATA_TYPE_SYSTEM, SqlTypeName.ANY)); RelDataType rowType = new RelRecordType(StructKind.FULLY_QUALIFIED, Arrays.asList(relDataType)); ImmutableList.Builder<ImmutableList<RexLiteral>> tuples = new ImmutableList.Builder<>(); for (int i = 0; i < INListLength; i++) { tuples.add(new ImmutableList.Builder<RexLiteral>().add(new RexBuilder(typeFactory).makeExactLiteral(new BigDecimal(i))).build()); } // Check original types. assertEquals(1, rowType.getFieldCount()); assertEquals(SqlTypeName.ANY, rowType.getFieldList().get(0).getType().getSqlTypeName()); // Construct ValuesRel final ValuesRel valuesRel = new ValuesRel(cluster, rowType, tuples.build(), traits); // Check the adjusted types. RelDataType adjustedRowType = valuesRel.getRowType(); assertEquals(1, adjustedRowType.getFieldCount()); assertEquals(SqlTypeName.INTEGER, adjustedRowType.getFieldList().get(0).getType().getSqlTypeName()); }
Example #7
Source File: TestValuesRel.java From dremio-oss with Apache License 2.0 | 6 votes |
@Test public void testCharValuesRelRowTypeAdjustment() { final int INListLength = 20; // Build RowType & Tuples RelDataTypeField relDataType = new RelDataTypeFieldImpl("ROW_VALUE", 0, new BasicSqlType(RelDataTypeSystemImpl.REL_DATA_TYPE_SYSTEM, SqlTypeName.ANY)); RelDataType rowType = new RelRecordType(StructKind.FULLY_QUALIFIED, Arrays.asList(relDataType)); ImmutableList.Builder<ImmutableList<RexLiteral>> tuples = new ImmutableList.Builder<>(); for (int i = 0; i < INListLength; ++i) { tuples.add(new ImmutableList.Builder<RexLiteral>().add(new RexBuilder(typeFactory).makeLiteral(charLiteralBuilder(i))).build()); } // Check original types. assertEquals(1, rowType.getFieldCount()); assertEquals(SqlTypeName.ANY, rowType.getFieldList().get(0).getType().getSqlTypeName()); // Construct ValuesRel final ValuesRel valuesRel = new ValuesRel(cluster, rowType, tuples.build(), traits); // Check the adjusted types. RelDataType adjustedRowType = valuesRel.getRowType(); assertEquals(1, adjustedRowType.getFieldCount()); assertEquals(SqlTypeName.CHAR, adjustedRowType.getFieldList().get(0).getType().getSqlTypeName()); assertEquals(INListLength - 1, adjustedRowType.getFieldList().get(0).getType().getPrecision()); }
Example #8
Source File: SamzaSqlJavaTypeFactoryImpl.java From samza with Apache License 2.0 | 6 votes |
private static RelDataType convertToSql(final RelDataTypeFactory typeFactory, RelDataType type) { if (type instanceof RelRecordType) { return typeFactory.createStructType( Lists.transform(type.getFieldList(), a0 -> convertToSql(typeFactory, a0.getType())), type.getFieldNames()); } if (type instanceof JavaType) { SqlTypeName typeName = JavaToSqlTypeConversionRules.instance().lookup(((JavaType) type).getJavaClass()); // For unknown sql type names, return ANY sql type to make Calcite validation not fail. if (typeName == null) { typeName = SqlTypeName.ANY; } return typeFactory.createTypeWithNullability( typeFactory.createSqlType(typeName), type.isNullable()); } else { return JavaTypeFactoryImpl.toSql(typeFactory, type); } }
Example #9
Source File: SamzaSqlValidator.java From samza with Apache License 2.0 | 6 votes |
private void validateOutput(RelRoot relRoot, RelSchemaProvider outputRelSchemaProvider) throws SamzaSqlValidatorException { LogicalProject project = (LogicalProject) relRoot.rel; RelRecordType projectRecord = (RelRecordType) project.getRowType(); RelRecordType outputRecord = (RelRecordType) QueryPlanner.getSourceRelSchema(outputRelSchemaProvider, new RelSchemaConverter()); // Handle any DELETE ops. if (projectRecord.getFieldList().stream().anyMatch(f -> f.getName().equalsIgnoreCase(SamzaSqlRelMessage.OP_NAME))) { validateDeleteOp(relRoot); return; } // Get Samza Sql schema along with Calcite schema. The reason is that the Calcite schema does not have a way // to represent optional fields while Samza Sql schema can represent optional fields. This is the reason that // we use SqlSchema in validating output. SqlSchema outputSqlSchema = QueryPlanner.getSourceSqlSchema(outputRelSchemaProvider); validateOutputRecords(outputSqlSchema, outputRecord, projectRecord, outputRelSchemaProvider); LOG.info("Samza Sql Validation finished successfully."); }
Example #10
Source File: JavaTypeFactoryImpl.java From Bats with Apache License 2.0 | 5 votes |
/** Creates a synthetic Java class whose fields have the same names and * relational types. */ private Type createSyntheticType(RelRecordType type) { final String name = "Record" + type.getFieldCount() + "_" + syntheticTypes.size(); final SyntheticRecordType syntheticType = new SyntheticRecordType(type, name); for (final RelDataTypeField recordField : type.getFieldList()) { final Type javaClass = getJavaClass(recordField.getType()); syntheticType.fields.add(new RecordFieldImpl(syntheticType, recordField.getName(), javaClass, recordField.getType().isNullable() && !Primitive.is(javaClass), Modifier.PUBLIC)); } return register(syntheticType); }
Example #11
Source File: JavaTypeFactoryImpl.java From calcite with Apache License 2.0 | 5 votes |
/** Converts a type in Java format to a SQL-oriented type. */ public static RelDataType toSql(final RelDataTypeFactory typeFactory, RelDataType type) { if (type instanceof RelRecordType) { return typeFactory.createTypeWithNullability( typeFactory.createStructType( type.getFieldList() .stream() .map(field -> toSql(typeFactory, field.getType())) .collect(Collectors.toList()), type.getFieldNames()), type.isNullable()); } else if (type instanceof JavaType) { SqlTypeName sqlTypeName = type.getSqlTypeName(); final RelDataType relDataType; if (SqlTypeUtil.isArray(type)) { // Transform to sql type, take care for two cases: // 1. type.getJavaClass() is collection with erased generic type // 2. ElementType returned by JavaType is also of JavaType, // and needs conversion using typeFactory final RelDataType elementType = toSqlTypeWithNullToAny( typeFactory, type.getComponentType()); relDataType = typeFactory.createArrayType(elementType, -1); } else if (SqlTypeUtil.isMap(type)) { final RelDataType keyType = toSqlTypeWithNullToAny( typeFactory, type.getKeyType()); final RelDataType valueType = toSqlTypeWithNullToAny( typeFactory, type.getValueType()); relDataType = typeFactory.createMapType(keyType, valueType); } else { relDataType = typeFactory.createSqlType(sqlTypeName); } return typeFactory.createTypeWithNullability(relDataType, type.isNullable()); } return type; }
Example #12
Source File: JavaTypeFactoryExtImpl.java From calcite with Apache License 2.0 | 5 votes |
public RelDataType createPdxType(PdxInstance pdxInstance) { final List<RelDataTypeField> list = new ArrayList<>(); for (String fieldName : pdxInstance.getFieldNames()) { Object field = pdxInstance.getField(fieldName); Type fieldType; if (field == null) { fieldType = String.class; } else if (field instanceof PdxInstance) { // Map Nested PDX structures as String. This relates with // GeodeUtils.convert case when clazz is Null. fieldType = Map.class; // RelDataType boza = createPdxType((PdxInstance) field); } else { fieldType = field.getClass(); } list.add( new RelDataTypeFieldImpl( fieldName, list.size(), createType(fieldType))); } return canonize(new RelRecordType(list)); }
Example #13
Source File: SamzaSqlValidator.java From samza with Apache License 2.0 | 5 votes |
private boolean compareFieldTypes(RelDataType outputFieldType, SqlFieldSchema sqlFieldSchema, RelDataType selectQueryFieldType, RelSchemaProvider outputRelSchemaProvider) { SqlTypeName outputSqlType = outputFieldType.getSqlTypeName(); SqlTypeName projectSqlType = selectQueryFieldType.getSqlTypeName(); if (projectSqlType == SqlTypeName.ANY || outputSqlType == SqlTypeName.ANY) { return true; } else if (outputSqlType != SqlTypeName.ROW && outputSqlType == projectSqlType) { return true; } switch (outputSqlType) { case CHAR: return projectSqlType == SqlTypeName.VARCHAR; case VARCHAR: return projectSqlType == SqlTypeName.CHAR; case BIGINT: return projectSqlType == SqlTypeName.INTEGER; case INTEGER: return projectSqlType == SqlTypeName.BIGINT; case FLOAT: return projectSqlType == SqlTypeName.DOUBLE; case DOUBLE: return projectSqlType == SqlTypeName.FLOAT; case ROW: try { validateOutputRecords(sqlFieldSchema.getRowSchema(), (RelRecordType) outputFieldType, (RelRecordType) selectQueryFieldType, outputRelSchemaProvider); } catch (SamzaSqlValidatorException e) { LOG.error("A field in select query does not match with the output schema.", e); return false; } return true; default: return false; } }
Example #14
Source File: SamzaSqlValidator.java From samza with Apache License 2.0 | 5 votes |
private void validateDeleteOp(RelRoot relRoot) throws SamzaSqlValidatorException { LogicalProject project = (LogicalProject) relRoot.rel; RelRecordType projectRecord = (RelRecordType) project.getRowType(); // In the case of DELETE op, only the key and DELETE op are required. if (projectRecord.getFieldCount() != 2) { throw new SamzaSqlValidatorException(String.format("Only two select query fields are expected for DELETE op." + " But there are %d fields given in the query.", projectRecord.getFieldCount())); } RelDataTypeField keyField = projectRecord.getField(SamzaSqlRelMessage.KEY_NAME, true, true); if (keyField == null) { throw new SamzaSqlValidatorException(String.format("Select query needs to specify '%s' field while using DELETE" + " op. Eg: 'SELECT myKey AS %s, '%s' AS %s FROM myTable'", SamzaSqlRelMessage.KEY_NAME, SamzaSqlRelMessage.KEY_NAME, SamzaSqlRelMessage.DELETE_OP, SamzaSqlRelMessage.OP_NAME)); } int keyIdx = projectRecord.getFieldList().indexOf(keyField); // Get the node corresponding to the special op. RexNode node = project.getProjects().get(1 - keyIdx); if (!node.toString().equals(String.format("'%s'", SamzaSqlRelMessage.DELETE_OP))) { throw new SamzaSqlValidatorException(String.format("%s op is not supported. Please note that only '%s' op is" + " currently supported. Eg:'SELECT myKey AS %s, '%s' AS %s FROM myStream'", node.toString(), SamzaSqlRelMessage.DELETE_OP, SamzaSqlRelMessage.KEY_NAME, SamzaSqlRelMessage.DELETE_OP, SamzaSqlRelMessage.OP_NAME)); } }
Example #15
Source File: CountToDirectScanUtils.java From Bats with Apache License 2.0 | 5 votes |
/** * For each aggregate call creates field based on its name with bigint type. * Constructs record type for created fields. * * @param aggregateRel aggregate relation expression * @param fieldNames field names * @return record type */ public static RelDataType constructDataType(Aggregate aggregateRel, Collection<String> fieldNames) { List<RelDataTypeField> fields = new ArrayList<>(); int fieldIndex = 0; for (String name : fieldNames) { RelDataTypeField field = new RelDataTypeFieldImpl( name, fieldIndex++, aggregateRel.getCluster().getTypeFactory().createSqlType(SqlTypeName.BIGINT)); fields.add(field); } return new RelRecordType(fields); }
Example #16
Source File: RewriteProjectToFlatten.java From Bats with Apache License 2.0 | 5 votes |
@Override public Prel visitProject(ProjectPrel node, Object unused) throws RelConversionException { ProjectPrel project = node; List<RexNode> exprList = new ArrayList<>(); boolean rewrite = false; List<RelDataTypeField> relDataTypes = new ArrayList<>(); int i = 0; RexNode flatttenExpr = null; for (RexNode rex : project.getChildExps()) { RexNode newExpr = rex; if (rex instanceof RexCall) { RexCall function = (RexCall) rex; String functionName = function.getOperator().getName(); if (functionName.equalsIgnoreCase("flatten") ) { rewrite = true; if (function.getOperands().size() != 1) { throw new RelConversionException("Flatten expression expects a single input."); } newExpr = function.getOperands().get(0); RexBuilder builder = new RexBuilder(factory); flatttenExpr = builder.makeInputRef( new RelDataTypeDrillImpl(new RelDataTypeHolder(), factory), i); } } relDataTypes.add(project.getRowType().getFieldList().get(i)); i++; exprList.add(newExpr); } if (rewrite == true) { // TODO - figure out what is the right setting for the traits Prel newChild = ((Prel)project.getInput(0)).accept(this, null); ProjectPrel newProject = new ProjectPrel(node.getCluster(), project.getTraitSet(), newChild, exprList, new RelRecordType(relDataTypes)); FlattenPrel flatten = new FlattenPrel(project.getCluster(), project.getTraitSet(), newProject, flatttenExpr); return flatten; } Prel child = ((Prel)project.getInput()).accept(this, null); return (Prel) project.copy(project.getTraitSet(), child, exprList, new RelRecordType(relDataTypes)); }
Example #17
Source File: DrillProjectRel.java From Bats with Apache License 2.0 | 5 votes |
public static DrillProjectRel convert(Project project, ConversionContext context) throws InvalidRelException{ RelNode input = context.toRel(project.getInput()); List<RelDataTypeField> fields = Lists.newArrayList(); List<RexNode> exps = Lists.newArrayList(); for(NamedExpression expr : project.getSelections()){ fields.add(new RelDataTypeFieldImpl(expr.getRef().getRootSegment().getPath(), fields.size(), context.getTypeFactory().createSqlType(SqlTypeName.ANY) )); exps.add(context.toRex(expr.getExpr())); } return new DrillProjectRel(context.getCluster(), context.getLogicalTraits(), input, exps, new RelRecordType(fields)); }
Example #18
Source File: AbstractIndexPlanGenerator.java From Bats with Apache License 2.0 | 5 votes |
protected RelDataType convertRowType(RelDataType origRowType, RelDataTypeFactory typeFactory) { if ( getRowKeyIndex(origRowType, origScan)>=0 ) { // row key already present return origRowType; } List<RelDataTypeField> fields = new ArrayList<>(); fields.addAll(origRowType.getFieldList()); fields.add(new RelDataTypeFieldImpl( ((DbGroupScan)IndexPlanUtils.getGroupScan(origScan)).getRowKeyName(), fields.size(), typeFactory.createSqlType(SqlTypeName.ANY))); return new RelRecordType(fields); }
Example #19
Source File: JavaTypeFactoryImpl.java From Bats with Apache License 2.0 | 5 votes |
private static RelDataType toSql(final RelDataTypeFactory typeFactory, RelDataType type, boolean mustSetNullability) { RelDataType sqlType = type; if (type instanceof RelRecordType) { // We do not need to change the nullability of the nested fields, // since it can be overridden by the existing implementation of createTypeWithNullability // when we treat the nullability of the root struct type. sqlType = typeFactory.createStructType( Lists.transform(type.getFieldList(), field -> toSql(typeFactory, field.getType(), false)), type.getFieldNames()); } else if (type instanceof JavaType) { sqlType = typeFactory.createSqlType(type.getSqlTypeName()); } return mustSetNullability ? typeFactory.createTypeWithNullability(sqlType, type.isNullable()) : sqlType; }
Example #20
Source File: SamzaSqlValidator.java From samza with Apache License 2.0 | 4 votes |
protected boolean isOptional(RelSchemaProvider outputRelSchemaProvider, String outputFieldName, RelRecordType projectRecord) { return false; }
Example #21
Source File: TestTransformer.java From dremio-oss with Apache License 2.0 | 4 votes |
@Test public void testUpdateSql() throws Exception { final String sql = "select foo, bar as b from tbl"; SqlParser parser = SqlParser.create(sql, new ParserConfig(Quoting.DOUBLE_QUOTE, 128)); final SqlNode sqlNode = parser.parseStmt(); final JavaTypeFactory typeFactory = JavaTypeFactoryImpl.INSTANCE; final RelDataType rowType = new RelRecordType(Arrays.<RelDataTypeField>asList( new RelDataTypeFieldImpl("foo", 0, typeFactory.createSqlType(SqlTypeName.INTEGER)), new RelDataTypeFieldImpl("b", 0, typeFactory.createSqlType(SqlTypeName.INTEGER)) )); final QueryMetadata metadata = Mockito.mock(QueryMetadata.class); Mockito.when(metadata.getSqlNode()).thenReturn(Optional.of(sqlNode)); Mockito.when(metadata.getRowType()).thenReturn(rowType); Mockito.when(metadata.getQuerySql()).thenReturn(sql); Mockito.when(metadata.getReferredTables()).thenReturn(Optional.absent()); TransformActor actor = new TransformActor(state, false, "test_user", null) { @Override protected com.dremio.service.jobs.metadata.proto.QueryMetadata getMetadata(SqlQuery query) { return com.dremio.service.jobs.metadata.proto.QueryMetadata.newBuilder() .setState(QuerySemantics.extract(metadata).get()) .build(); } @Override protected boolean hasMetadata() { return true; } @Override protected com.dremio.service.jobs.metadata.proto.QueryMetadata getMetadata() { throw new IllegalStateException("not implemented"); } @Override protected Optional<BatchSchema> getBatchSchema() { throw new IllegalStateException("not implemented"); } @Override protected Optional<List<ParentDatasetInfo>> getParents() { throw new IllegalStateException("not implemented"); } @Override protected Optional<List<FieldOrigin>> getFieldOrigins() { throw new IllegalStateException("not implemented"); } @Override protected Optional<List<ParentDataset>> getGrandParents() { throw new IllegalStateException("not implemented"); } }; TransformResult result = new TransformUpdateSQL(sql).accept(actor); VirtualDatasetState newState = result.getNewState(); assertEquals(2, newState.getColumnsList().size()); assertEquals("foo", newState.getColumnsList().get(0).getName()); assertEquals(new ExpColumnReference("foo").wrap(), newState.getColumnsList().get(0).getValue()); assertEquals("b", newState.getColumnsList().get(1).getName()); assertEquals(new ExpColumnReference("bar").wrap(), newState.getColumnsList().get(1).getValue()); }
Example #22
Source File: ConvertCountToDirectScan.java From dremio-oss with Apache License 2.0 | 4 votes |
private RelDataType getCountRowType(RelDataTypeFactory typeFactory) { List<RelDataTypeField> fields = Lists.newArrayList(); fields.add(new RelDataTypeFieldImpl("count", 0, typeFactory.createSqlType(SqlTypeName.BIGINT))); return new RelRecordType(fields); }
Example #23
Source File: RelSchemaConverter.java From samza with Apache License 2.0 | 4 votes |
private RelDataType convertRecordType(SqlSchema schema) { List<RelDataTypeField> relFields = getRelFields(schema.getFields()); return new RelRecordType(relFields); }
Example #24
Source File: MoreRelOptUtil.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public Boolean visitCall(RexCall call) { if (call.getOperator().getName().equalsIgnoreCase("contains")) { if (!checkOrigin) { return true; } // Check origin final Set<RelColumnOrigin> origins; if (index >= 0) { origins = mq.getColumnOrigins(node, index); } else { List<RelDataTypeField> fields = ImmutableList.<RelDataTypeField>of(new RelDataTypeFieldImpl("ContainsTemp", 0, call.getType())); Project temporary = new LogicalProject(node.getCluster(), node.getTraitSet().plus(Convention.NONE), node.getInput(0), ImmutableList.of(call), new RelRecordType(fields)); origins = mq.getColumnOrigins(temporary, 0); } boolean supportContains = true; if (origins == null) { supportContains = false; } else { for (RelColumnOrigin column : origins) { if (column.getOriginTable() == null) { supportContains = false; } else { NamespaceTable namespaceTable2 = column.getOriginTable().unwrap(NamespaceTable.class); if (namespaceTable2 != null) { if(!namespaceTable2.getStoragePluginId().getCapabilities().getCapability(SourceCapabilities.SUPPORTS_CONTAINS)){ supportContains = false; } } else { supportContains = false; } } } } if (!supportContains) { throw UserException.unsupportedError().message("Contains operator is not supported for the table, %s", call).build(logger); } return true; } for (RexNode op : call.getOperands()) { Boolean opResult = op.accept(this); if (opResult != null && opResult.booleanValue()) { return true; } } return false; }
Example #25
Source File: JavaTypeFactoryExtImpl.java From calcite with Apache License 2.0 | 4 votes |
public RelDataType createPdxType2(PdxInstance pdxInstance) { final List<RelDataTypeField> list = new ArrayList<>(); recursiveCreatePdxType(pdxInstance, list, ""); return canonize(new RelRecordType(list)); }
Example #26
Source File: FunctionalIndexHelper.java From Bats with Apache License 2.0 | 4 votes |
/** * if a field in rowType serves only the to-be-replaced column(s), we should replace it with new name "$1", * otherwise we should keep this dataTypeField and add a new one for "$1" * @param origScan the original scan whose rowtype is to be rewritten * @param indexContext the index plan context * @param functionInfo functional index information that may impact rewrite * @return */ public static RelDataType rewriteFunctionalRowType(RelNode origScan, IndexCallContext indexContext, FunctionalIndexInfo functionInfo, Collection<SchemaPath> addedPaths) { RelDataType origRowType = origScan.getRowType(); if (!functionInfo.hasFunctional()) { return origRowType; } List<RelDataTypeField> fields = Lists.newArrayList(); Set<String> leftOutFieldNames = Sets.newHashSet(); if (indexContext.getLeftOutPathsInFunctions() != null) { for (LogicalExpression expr : indexContext.getLeftOutPathsInFunctions()) { leftOutFieldNames.add(((SchemaPath) expr).getRootSegmentPath()); } } Set<String> fieldInFunctions = Sets.newHashSet(); for (SchemaPath path: functionInfo.allPathsInFunction()) { fieldInFunctions.add(path.getRootSegmentPath()); } RelDataTypeFactory typeFactory = origScan.getCluster().getTypeFactory(); for ( RelDataTypeField field: origRowType.getFieldList()) { final String fieldName = field.getName(); if (fieldInFunctions.contains(fieldName)) { if (!leftOutFieldNames.contains(fieldName)) { continue; } } fields.add(new RelDataTypeFieldImpl( SchemaPath.parseFromString(fieldName).getRootSegmentPath(), fields.size(), typeFactory.createSqlType(SqlTypeName.ANY))); } final Collection<SchemaPath> toAddToRowType = (addedPaths == null)? functionInfo.allNewSchemaPaths() : addedPaths; for (SchemaPath dollarPath : toAddToRowType) { fields.add( new RelDataTypeFieldImpl(dollarPath.getRootSegmentPath(), fields.size(), origScan.getCluster().getTypeFactory().createSqlType(SqlTypeName.ANY))); } return new RelRecordType(fields); }