use of org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject in project hive by apache.
the class JDBCProjectPushDownRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
LOG.debug("JDBCProjectPushDownRule has been called");
final HiveProject project = call.rel(0);
final HiveJdbcConverter converter = call.rel(1);
JdbcProject jdbcProject = new JdbcProject(project.getCluster(), project.getTraitSet().replace(converter.getJdbcConvention()), converter.getInput(), project.getProjects(), project.getRowType());
call.transformTo(converter.copy(converter.getTraitSet(), jdbcProject));
}
use of org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject in project hive by apache.
the class HiveCalciteUtil method getTopLevelSelect.
/**
* Get top level select starting from root. Assumption here is root can only
* be Sort & Project. Also the top project should be at most 2 levels below
* Sort; i.e Sort(Limit)-Sort(OB)-Select
*
* @param rootRel
* @return
*/
public static Pair<RelNode, RelNode> getTopLevelSelect(final RelNode rootRel) {
RelNode tmpRel = rootRel;
RelNode parentOforiginalProjRel = rootRel;
RelNode originalProjRel = null;
while (tmpRel != null) {
if (tmpRel instanceof HiveProject || tmpRel instanceof HiveTableFunctionScan) {
originalProjRel = tmpRel;
break;
}
parentOforiginalProjRel = tmpRel;
tmpRel = tmpRel.getInput(0);
}
return (new Pair<RelNode, RelNode>(parentOforiginalProjRel, originalProjRel));
}
use of org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject in project hive by apache.
the class HiveRelFieldTrimmer method trimFields.
/**
* Variant of {@link #trimFields(RelNode, ImmutableBitSet, Set)} for
* {@link org.apache.calcite.rel.logical.LogicalProject}.
*/
public TrimResult trimFields(Project project, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields) {
// set columnAccessInfo for ViewColumnAuthorization
final ColumnAccessInfo columnAccessInfo = COLUMN_ACCESS_INFO.get();
final Map<HiveProject, Table> viewProjectToTableSchema = VIEW_PROJECT_TO_TABLE_SCHEMA.get();
if (columnAccessInfo != null && viewProjectToTableSchema != null && viewProjectToTableSchema.containsKey(project)) {
for (Ord<RexNode> ord : Ord.zip(project.getProjects())) {
if (fieldsUsed.get(ord.i)) {
Table tab = viewProjectToTableSchema.get(project);
columnAccessInfo.add(tab.getCompleteName(), tab.getAllCols().get(ord.i).getName());
}
}
}
return super.trimFields(project, fieldsUsed, extraFields);
}
use of org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject in project hive by apache.
the class HiveRelFieldTrimmer method project.
private static RelNode project(DruidQuery dq, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields, RelBuilder relBuilder) {
final int fieldCount = dq.getRowType().getFieldCount();
if (fieldsUsed.equals(ImmutableBitSet.range(fieldCount)) && extraFields.isEmpty()) {
return dq;
}
final List<RexNode> exprList = new ArrayList<>();
final List<String> nameList = new ArrayList<>();
final RexBuilder rexBuilder = dq.getCluster().getRexBuilder();
final List<RelDataTypeField> fields = dq.getRowType().getFieldList();
// Project the subset of fields.
for (int i : fieldsUsed) {
RelDataTypeField field = fields.get(i);
exprList.add(rexBuilder.makeInputRef(dq, i));
nameList.add(field.getName());
}
// extra fields, but we don't.)
for (RelDataTypeField extraField : extraFields) {
exprList.add(rexBuilder.ensureType(extraField.getType(), rexBuilder.constantNull(), true));
nameList.add(extraField.getName());
}
HiveProject hp = (HiveProject) relBuilder.push(dq).project(exprList, nameList).build();
hp.setSynthetic();
return hp;
}
Aggregations