@Override public StringBuilder digest(StringBuilder buf) { return buf.append("Scan(table: ") .append(rel.getTable().getQualifiedName()).append(")"); } }
int rowIDPos = tableScan.getTable().getRowType().getField( VirtualColumn.ROWID.getName(), false, false).getIndex(); RexNode rowIDFieldAccess = rexBuilder.makeFieldAccess( rexBuilder.makeInputRef(tableScan.getTable().getRowType().getFieldList().get(rowIDPos).getType(), rowIDPos), 0); rexBuilder.makeCall( SqlStdOperatorTable.LESS_THAN_OR_EQUAL, ImmutableList.of(rowIDFieldAccess, literalHighWatermark))); for (long invalidTxn : tableMaterializationTxnList.getInvalidWriteIds()) { final RexNode literalInvalidTxn = rexBuilder.makeLiteral( rexBuilder.makeCall( SqlStdOperatorTable.NOT_EQUALS, ImmutableList.of(rowIDFieldAccess, literalInvalidTxn)));
final RelOptTable relOptTable = tableModify.getTable(); final Prepare.CatalogReader catalogReader = tableModify.getCatalogReader(); final RelNode convertedInput = convert(input, input.getTraitSet().replace(StreamsLogicalConvention.INSTANCE)); final TableModify.Operation operation = tableModify.getOperation(); final List<String> updateColumnList = tableModify.getUpdateColumnList(); StormTable stormTable = tableModify.getTable().unwrap(StormTable.class); if (stormTable != null) { primaryKey = stormTable.primaryKey(); } else { StormStreamableTable streamableTable = tableModify.getTable().unwrap(StormStreamableTable.class); if (streamableTable != null) { primaryKey = streamableTable.primaryKey(); final Table table = tableModify.getTable().unwrap(Table.class);
List<RexNode> nullableNodes = null; for (RelTableRef tRef : fkTables) { List<RelReferentialConstraint> constraints = tRef.getTable().getReferentialConstraints(); for (RelReferentialConstraint constraint : constraints) { if (constraint.getTargetQualifiedName().equals(nonFkTableQName)) { int foreignKeyPos = constraint.getColumnPairs().get(pos).source; RelDataType foreignKeyColumnType = tRef.getTable().getRowType().getFieldList().get(foreignKeyPos).getType(); RexTableInputRef foreignKeyColumnRef = RexTableInputRef.of(tRef, foreignKeyPos, foreignKeyColumnType); int uniqueKeyPos = constraint.getColumnPairs().get(pos).target; RexTableInputRef uniqueKeyColumnRef = RexTableInputRef.of(nonFkTable, uniqueKeyPos, nonFkTable.getTable().getRowType().getFieldList().get(uniqueKeyPos).getType()); if (ecT.getEquivalenceClassesMap().containsKey(uniqueKeyColumnRef) && ecT.getEquivalenceClassesMap().get(uniqueKeyColumnRef).contains(foreignKeyColumnRef)) { if (foreignKeyColumnType.isNullable()) { if (joinType == JoinRelType.INNER) {
join = join.copy(join.getTraitSet(), join.getCluster().getRexBuilder().makeLiteral(true), join.getLeft(), join.getRight(), JoinRelType.INNER, false); final List<String> nonFkTableQName = nonFkTable.getQualifiedName(); for (RelTableRef tRef : fkTables) { List<RelReferentialConstraint> constraints = tRef.getTable().getReferentialConstraints(); for (RelReferentialConstraint constraint : constraints) { if (constraint.getTargetQualifiedName().equals(nonFkTableQName)) { int foreignKeyPos = constraint.getColumnPairs().get(pos).source; RelDataType foreignKeyColumnType = tRef.getTable().getRowType().getFieldList().get(foreignKeyPos).getType(); RexTableInputRef foreignKeyColumnRef = RexTableInputRef.of(tRef, foreignKeyPos, foreignKeyColumnType); int uniqueKeyPos = constraint.getColumnPairs().get(pos).target; RexTableInputRef uniqueKeyColumnRef = RexTableInputRef.of(nonFkTable, uniqueKeyPos, nonFkTable.getTable().getRowType().getFieldList().get(uniqueKeyPos).getType()); if (ecT.getEquivalenceClassesMap().containsKey(uniqueKeyColumnRef) && ecT.getEquivalenceClassesMap().get(uniqueKeyColumnRef).contains(foreignKeyColumnRef)) { int nFieldsLeft = join.getLeft().getRowType().getFieldList().size(); int nFieldsRight = join.getRight().getRowType().getFieldList().size(); int nSysFields = join.getSystemFieldList().size(); ImmutableBitSet rightFieldsBitSet = ImmutableBitSet.range(nSysFields + nFieldsLeft,
identifierList, validator.getValidationErrorFunction()); final ImmutableList.Builder<RelDataTypeField> builder = ImmutableList.builder(); builder.addAll(this.extendedFields); builder.addAll( checkExtendedColumnTypes(extendList); final RelOptTable relOptTable = ((RelOptTable) table).extend(extendedFields); final SqlValidatorTable validatorTable = relOptTable.unwrap(SqlValidatorTable.class); return new TableNamespace(validator, validatorTable, ImmutableList.of());
/** @see #dispatch */ public Result visit(TableScan e) { final SqlIdentifier identifier = new SqlIdentifier(e.getTable().getQualifiedName(), SqlParserPos.ZERO); return result(identifier, ImmutableList.of(Clause.FROM), e, null); }
/** Creates an EnumerableTableScan. */ public static EnumerableTableScan create(RelOptCluster cluster, RelOptTable relOptTable) { final Table table = relOptTable.unwrap(Table.class); Class elementType = EnumerableTableScan.deduceElementType(table); final RelTraitSet traitSet = cluster.traitSetOf(EnumerableConvention.INSTANCE) .replaceIfs(RelCollationTraitDef.INSTANCE, () -> { if (table != null) { return table.getStatistic().getCollations(); } return ImmutableList.of(); }); return new EnumerableTableScan(cluster, traitSet, relOptTable, elementType); }
private Prel newScan(RelDataType rowType, double rowCount, double splitRatio) throws Exception { TableMetadata metadata = Mockito.mock(TableMetadata.class); when(metadata.getName()).thenReturn(new NamespaceKey(ImmutableList.of("sys", "version"))); when(metadata.getSchema()).thenReturn(SystemTable.VERSION.getSchema()); when(metadata.getSplitRatio()).thenReturn(splitRatio); StoragePluginId pluginId = new StoragePluginId(new SourceConfig().setConfig(new SystemPluginConf().toBytesString()), new SystemPluginConf(), SourceCapabilities.NONE); when(metadata.getStoragePluginId()).thenReturn(pluginId); List<SchemaPath> columns = FluentIterable.from(SystemTable.VERSION.getSchema()).transform(input -> SchemaPath.getSimplePath(input.getName())).toList(); final RelOptTable relOptTable = Mockito.mock(RelOptTable.class); when(relOptTable.getRowCount()).thenReturn(rowCount); return new SystemScanPrel(cluster, traits, relOptTable, metadata, columns, 1.0d, rowType); }
@Override public RelNode visit(TableScan scan) { RelOptTable relOptTable = scan.getTable(); final Table table = relOptTable.unwrap(Table.class); if (table.equals(starTable.tables.get(0))) { Mappings.TargetMapping mapping = Mappings.createShiftMapping( starRelOptTable.getRowType().getFieldCount(), 0, 0, relOptTable.getRowType().getFieldCount()); final RelOptCluster cluster = scan.getCluster(); final RelNode scan2 = starRelOptTable.toRel(ViewExpanders.simpleContext(cluster)); return RelOptUtil.createProject(scan2, Mappings.asList(mapping.inverse())); } return scan; }
@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) { // Cost factor for pushing filters double f = filters.isEmpty() ? 1d : 0.5d; // Cost factor for pushing fields // The "+ 2d" on top and bottom keeps the function fairly smooth. double p = ((double) projects.size() + 2d) / ((double) table.getRowType().getFieldCount() + 2d); // Multiply the cost by a factor that makes a scan more attractive if // filters and projects are pushed to the table scan return super.computeSelfCost(planner, mq) .multiplyBy(f * p * 0.01d); }
public Column column(int table, int column) { int i = 0; for (LatticeNode descendant : rootNode.descendants) { if (table-- == 0) { break; } i += descendant.table.t.getRowType().getFieldCount(); } return baseColumns.get(i + column); }
@Override public RelDataType deriveRowType() { final List<RelDataTypeField> fieldList = table.getRowType().getFieldList(); final RelDataTypeFactory.FieldInfoBuilder builder = getCluster().getTypeFactory().builder(); for (int field : fields) { builder.add(fieldList.get(field)); } return getCluster().getTypeFactory().createStructType(builder); }
@Override public ColumnStrategy generationStrategy(RelOptTable table, int iColumn) { final RelDataTypeField field = table.getRowType().getFieldList().get(iColumn); if (defaultColumns.contains(field.getName())) { return ColumnStrategy.DEFAULT; } return super.generationStrategy(table, iColumn); }
/** Returns the row type of a table after any {@link ColumnStrategy#VIRTUAL} * columns have been removed. This is the type of the records that are * actually stored. */ public static RelDataType realRowType(RelOptTable table) { final RelDataType rowType = table.getRowType(); final List<ColumnStrategy> strategies = columnStrategies(table); if (!strategies.contains(ColumnStrategy.VIRTUAL)) { return rowType; } final RelDataTypeFactory.Builder builder = table.getRelOptSchema().getTypeFactory().builder(); for (RelDataTypeField field : rowType.getFieldList()) { if (strategies.get(field.getIndex()) != ColumnStrategy.VIRTUAL) { builder.add(field); } } return builder.build(); }
@Override public JoinCondition apply(Pair<Integer, Integer> pair) { final RelColumnOrigin leftColumnOrigin = Iterables.getOnlyElement(relMetadataQuery.getColumnOrigins(joinPrel.getLeft(), pair.left)); final RelColumnOrigin rightColumnOrigin = Iterables.getOnlyElement(relMetadataQuery.getColumnOrigins(joinPrel.getRight(), pair.right)); final RelOptTable leftTable = leftColumnOrigin.getOriginTable(); final RelOptTable rightTable = rightColumnOrigin.getOriginTable(); int leftOrdinal = leftColumnOrigin.getOriginColumnOrdinal(); int rightOrdinal = rightColumnOrigin.getOriginColumnOrdinal(); return new JoinCondition() .setBuildSideColumn(rightTable.getRowType().getFieldList().get(rightOrdinal).getName()) .setProbeSideColumn(leftTable.getRowType().getFieldList().get(leftOrdinal).getName()) .setBuildSideTableId(tables.get(rightTable.getQualifiedName())) .setProbeSideTableId(tables.get(leftTable.getQualifiedName())); } })
@Override public void visit(RelNode node, int ordinal, RelNode parent) { if (node instanceof TableScan) { final RelOptCluster cluster = node.getCluster(); final RelOptTable.ToRelContext context = ViewExpanders.simpleContext(cluster); final RelNode r = node.getTable().toRel(context); planner.registerClass(r); } super.visit(node, ordinal, parent); } };
public static PartialDruidQuery create(final RelNode scanRel) { final Supplier<RelBuilder> builderSupplier = () -> RelFactories.LOGICAL_BUILDER.create( scanRel.getCluster(), scanRel.getTable().getRelOptSchema() ); return new PartialDruidQuery(builderSupplier, scanRel, null, null, null, null, null, null, null, null); }
private void fetchColStats(RelNode key, TableScan tableAccessRel, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields) { final List<Integer> iRefSet = Lists.newArrayList(); if (key instanceof Project) { final Project project = (Project) key; for (RexNode rx : project.getChildExps()) { iRefSet.addAll(HiveCalciteUtil.getInputRefs(rx)); } } else { final int fieldCount = tableAccessRel.getRowType().getFieldCount(); if (fieldsUsed.equals(ImmutableBitSet.range(fieldCount)) && extraFields.isEmpty()) { // get all cols iRefSet.addAll(ImmutableBitSet.range(fieldCount).asList()); } } //Remove any virtual cols if (tableAccessRel instanceof HiveTableScan) { iRefSet.removeAll(((HiveTableScan)tableAccessRel).getVirtualCols()); } if (!iRefSet.isEmpty()) { final RelOptTable table = tableAccessRel.getTable(); if (table instanceof RelOptHiveTable) { ((RelOptHiveTable) table).getColStat(iRefSet, true); LOG.debug("Got col stats for {} in {}", iRefSet, tableAccessRel.getTable().getQualifiedName()); } } }
@Override public RelOptMaterialization apply(RelOptMaterialization materialization) { final RelNode viewScan = materialization.tableRel; final RelNode newViewScan; if (viewScan instanceof DruidQuery) { final DruidQuery dq = (DruidQuery) viewScan; newViewScan = DruidQuery.create(optCluster, optCluster.traitSetOf(HiveRelNode.CONVENTION), viewScan.getTable(), dq.getDruidTable(), ImmutableList.<RelNode>of(dq.getTableScan())); } else { newViewScan = new HiveTableScan(optCluster, optCluster.traitSetOf(HiveRelNode.CONVENTION), (RelOptHiveTable) viewScan.getTable(), viewScan.getTable().getQualifiedName().get(0), null, false, false); } return new RelOptMaterialization(newViewScan, materialization.queryRel, null); } }