private ColStatistics extractColStats(RexInputRef ref) { RelColumnOrigin columnOrigin = this.metadataProvider.getColumnOrigin(filterOp, ref.getIndex()); if (columnOrigin != null) { RelOptHiveTable table = (RelOptHiveTable) columnOrigin.getOriginTable(); if (table != null) { ColStatistics colStats = table.getColStat(Lists.newArrayList(columnOrigin.getOriginColumnOrdinal()), false).get(0); if (colStats != null && StatsUtils.areColumnStatsUptoDateForQueryAnswering( table.getHiveTableMD(), table.getHiveTableMD().getParameters(), colStats.getColumnName())) { return colStats; } } } return null; }
public static void checkColumnOrigin( RelColumnOrigin rco, String expectedTableName, String expectedColumnName, boolean expectedDerived) { RelOptTable actualTable = rco.getOriginTable(); List<String> actualTableName = actualTable.getQualifiedName(); assertEquals( Iterables.getLast(actualTableName), expectedTableName); assertEquals( actualTable.getRowType() .getFieldList() .get(rco.getOriginColumnOrdinal()) .getName(), expectedColumnName); assertEquals( rco.isDerived(), expectedDerived); }
private Set<RelColumnOrigin> createDerivedColumnOrigins( Set<RelColumnOrigin> inputSet) { if (inputSet == null) { return null; } final Set<RelColumnOrigin> set = new HashSet<>(); for (RelColumnOrigin rco : inputSet) { RelColumnOrigin derived = new RelColumnOrigin( rco.getOriginTable(), rco.getOriginColumnOrdinal(), true); set.add(derived); } return set; } }
private Long extractRowCount(RexInputRef ref) { RelColumnOrigin columnOrigin = this.metadataProvider.getColumnOrigin(filterOp, ref.getIndex()); if (columnOrigin != null) { RelOptHiveTable table = (RelOptHiveTable) columnOrigin.getOriginTable(); if (table != null) { if (StatsUtils.areBasicStatsUptoDateForQueryAnswering(table.getHiveTableMD(), table.getHiveTableMD().getParameters())) { return StatsUtils.getNumRows(table.getHiveTableMD()); } } } return null; }
return false; if (leftOrigin.getOriginColumnOrdinal() != rightOrigin.getOriginColumnOrdinal()) { return false;
/** * Determines the origin of a column, provided the column maps to a single * column that isn't derived. * * @see #getColumnOrigins(org.apache.calcite.rel.RelNode, int) * * @param rel the RelNode of the column * @param column the offset of the column whose origin we are trying to * determine * * @return the origin of a column provided it's a simple column; otherwise, * returns null */ public RelColumnOrigin getColumnOrigin(RelNode rel, int column) { final Set<RelColumnOrigin> origins = getColumnOrigins(rel, column); if (origins == null || origins.size() != 1) { return null; } final RelColumnOrigin origin = Iterables.getOnlyElement(origins); return origin.isDerived() ? null : origin; }
public Set<RelColumnOrigin> getColumnOrigins(TableScan tableScan, RelMetadataQuery mq, int iOutputColumn) { final Set<RelColumnOrigin> set = new HashSet<>(); RelOptTable table = tableScan.getTable(); if (table == null) { return null; } if (table.getRowType() != tableScan.getRowType()) { String columnName = tableScan.getRowType().getFieldNames().get(iOutputColumn); int newOutputColumn = 0; for (String tableCol : table.getRowType().getFieldNames()) { if (tableCol.equals(columnName)) { set.add(new RelColumnOrigin(table, newOutputColumn, false)); return set; } newOutputColumn++; } } else { set.add(new RelColumnOrigin(table, iOutputColumn, false)); } return set; }
public static void checkColumnOrigin( RelColumnOrigin rco, String expectedTableName, String expectedColumnName, boolean expectedDerived) { RelOptTable actualTable = rco.getOriginTable(); List<String> actualTableName = actualTable.getQualifiedName(); assertEquals( Iterables.getLast(actualTableName), expectedTableName); assertEquals( actualTable.getRowType() .getFieldList() .get(rco.getOriginColumnOrdinal()) .getName(), expectedColumnName); assertEquals( rco.isDerived(), expectedDerived); }
private Set<RelColumnOrigin> createDerivedColumnOrigins( Set<RelColumnOrigin> inputSet) { if (inputSet == null) { return null; } final Set<RelColumnOrigin> set = new HashSet<>(); for (RelColumnOrigin rco : inputSet) { RelColumnOrigin derived = new RelColumnOrigin( rco.getOriginTable(), rco.getOriginColumnOrdinal(), true); set.add(derived); } return set; } }
/** * @param origin * @return the table */ public static List<String> getTable(RelColumnOrigin origin) { return origin.getOriginTable().getQualifiedName(); }
return false; if (leftOrigin.getOriginColumnOrdinal() != rightOrigin.getOriginColumnOrdinal()) { return false;
/** * Determines the origin of a column, provided the column maps to a single * column that isn't derived. * * @see #getColumnOrigins(org.apache.calcite.rel.RelNode, int) * * @param rel the RelNode of the column * @param column the offset of the column whose origin we are trying to * determine * * @return the origin of a column provided it's a simple column; otherwise, * returns null */ public RelColumnOrigin getColumnOrigin(RelNode rel, int column) { final Set<RelColumnOrigin> origins = getColumnOrigins(rel, column); if (origins == null || origins.size() != 1) { return null; } final RelColumnOrigin origin = Iterables.getOnlyElement(origins); return origin.isDerived() ? null : origin; }
public Set<RelColumnOrigin> getColumnOrigins(RelNode rel, RelMetadataQuery mq, int iOutputColumn) { // NOTE jvs 28-Mar-2006: We may get this wrong for a physical table // expression which supports projections. In that case, // it's up to the plugin writer to override with the // correct information. if (rel.getInputs().size() > 0) { // No generic logic available for non-leaf rels. return null; } final Set<RelColumnOrigin> set = new HashSet<>(); RelOptTable table = rel.getTable(); if (table == null) { // Somebody is making column values up out of thin air, like a // VALUES clause, so we return an empty set. return set; } // Detect the case where a physical table expression is performing // projection, and say we don't know instead of making any assumptions. // (Theoretically we could try to map the projection using column // names.) This detection assumes the table expression doesn't handle // rename as well. if (table.getRowType() != rel.getRowType()) { return null; } set.add(new RelColumnOrigin(table, iOutputColumn, false)); return set; }
private List<RexNode> extractFilterPreds(Filter filterOp) { List<RexNode> conjs = new ArrayList<>(); for (RexNode r : HiveRelOptUtil.conjunctions(filterOp.getCondition())) { if (r.getKind() == SqlKind.IS_NOT_NULL) { RexCall isNotNullNode = (RexCall) r; if (RexUtil.isReferenceOrAccess(isNotNullNode.getOperands().get(0), true)) { ImmutableBitSet ref = RelOptUtil.InputFinder.bits(isNotNullNode); RelColumnOrigin co = mq.getColumnOrigin(filterOp, ref.nextSetBit(0)); if (co == null) { // We add it back conjs.add(r); continue; } RelOptHiveTable table = (RelOptHiveTable) co.getOriginTable(); List<ColStatistics> colStats = table.getColStat(ImmutableList.of(co.getOriginColumnOrdinal()), true); if (colStats == null || colStats.isEmpty() || colStats.get(0).getNumNulls() != 0) { // We add it back conjs.add(r); } } } else { conjs.add(r); } } return conjs; }
if (origins == null || origins.size() != 1 || origins.iterator().next().isDerived()) { throw failed(); final RelOptTable originTable = origin.getOriginTable(); final String tableFieldname = originTable.getRowType().getFieldNames().get(origin.getOriginColumnOrdinal());
private Set<RelColumnOrigin> createDerivedColumnOrigins( Set<RelColumnOrigin> inputSet) { if (inputSet == null) { return null; } final Set<RelColumnOrigin> set = new HashSet<>(); for (RelColumnOrigin rco : inputSet) { RelColumnOrigin derived = new RelColumnOrigin( rco.getOriginTable(), rco.getOriginColumnOrdinal(), true); set.add(derived); } return set; } }
/** * Determines the origin of a {@link RelNode}, provided it maps to a single * table, optionally with filtering and projection. * * @param rel the RelNode * * @return the table, if the RelNode is a simple table; otherwise null */ public RelOptTable getTableOrigin(RelNode rel) { // Determine the simple origin of the first column in the // RelNode. If it's simple, then that means that the underlying // table is also simple, even if the column itself is derived. final Set<RelColumnOrigin> colOrigins = getColumnOrigins(rel, 0); if (colOrigins == null || colOrigins.size() == 0) { return null; } return colOrigins.iterator().next().getOriginTable(); }
if (colOrigin != null) { leftFactorColMapping.put( colOrigin.getOriginColumnOrdinal(), i); leftFactorColMapping.get(colOrigin.getOriginColumnOrdinal()); if (leftOffset == null) { continue;
List<String> table = Origins.getTable(relColumnOrigin); String colName = Origins.getColName(relColumnOrigin); namedOrigins.add(new Origin(colName, relColumnOrigin.isDerived()).setTableList(table));
public Set<RelColumnOrigin> getColumnOrigins(RelNode rel, RelMetadataQuery mq, int iOutputColumn) { // NOTE jvs 28-Mar-2006: We may get this wrong for a physical table // expression which supports projections. In that case, // it's up to the plugin writer to override with the // correct information. if (rel.getInputs().size() > 0) { // No generic logic available for non-leaf rels. return null; } final Set<RelColumnOrigin> set = new HashSet<>(); RelOptTable table = rel.getTable(); if (table == null) { // Somebody is making column values up out of thin air, like a // VALUES clause, so we return an empty set. return set; } // Detect the case where a physical table expression is performing // projection, and say we don't know instead of making any assumptions. // (Theoretically we could try to map the projection using column // names.) This detection assumes the table expression doesn't handle // rename as well. if (table.getRowType() != rel.getRowType()) { return null; } set.add(new RelColumnOrigin(table, iOutputColumn, false)); return set; }