return genJoinRelNode(leftRel, rightRel, hiveJoinType, joinCond);
}
private RelNode genTableLogicalPlan(String tableAlias, QB qb) throws SemanticException {
RowResolver rr = new RowResolver();
HiveTableScanRel tableRel = null;
try {
// 1. If the table has a Sample specified, bail from Optiq path.
if ( qb.getParseInfo().getTabSample(tableAlias) != null ||
SemanticAnalyzer.this.nameToSplitSample.containsKey(tableAlias)) {
String msg = String.format("Table Sample specified for %s." +
" Currently we don't support Table Sample clauses in CBO," +
" turn off cbo for queries on tableSamples.", tableAlias);
LOG.debug(msg);
throw new OptiqSemanticException(msg);
}
// 2. Get Table Metadata
Table tab = qb.getMetaData().getSrcForAlias(tableAlias);
// 3. Get Table Logical Schema (Row Type)
// NOTE: Table logical schema = Non Partition Cols + Partition Cols +
// Virtual Cols
// 3.1 Add Column info for non partion cols (Object Inspector fields)
StructObjectInspector rowObjectInspector = (StructObjectInspector) tab.getDeserializer()
.getObjectInspector();
List<? extends StructField> fields = rowObjectInspector.getAllStructFieldRefs();
ColumnInfo colInfo;
String colName;
ArrayList<ColumnInfo> cInfoLst = new ArrayList<ColumnInfo>();
for (int i = 0; i < fields.size(); i++) {
colName = fields.get(i).getFieldName();
colInfo = new ColumnInfo(
fields.get(i).getFieldName(),
TypeInfoUtils.getTypeInfoFromObjectInspector(fields.get(i).getFieldObjectInspector()),
tableAlias, false);
colInfo.setSkewedCol((isSkewedCol(tableAlias, qb, colName)) ? true : false);
rr.put(tableAlias, colName, colInfo);
cInfoLst.add(colInfo);
}
// TODO: Fix this
ArrayList<ColumnInfo> nonPartitionColumns = new ArrayList<ColumnInfo>(cInfoLst);
ArrayList<ColumnInfo> partitionColumns = new ArrayList<ColumnInfo>();
// 3.2 Add column info corresponding to partition columns
for (FieldSchema part_col : tab.getPartCols()) {
colName = part_col.getName();
colInfo = new ColumnInfo(colName,
TypeInfoFactory.getPrimitiveTypeInfo(part_col.getType()), tableAlias, true);
rr.put(tableAlias, colName, colInfo);
cInfoLst.add(colInfo);
partitionColumns.add(colInfo);
}
// 3.3 Add column info corresponding to virtual columns
Iterator<VirtualColumn> vcs = VirtualColumn.getRegistry(conf).iterator();
while (vcs.hasNext()) {
VirtualColumn vc = vcs.next();
colInfo = new ColumnInfo(vc.getName(), vc.getTypeInfo(), tableAlias, true,
vc.getIsHidden());
rr.put(tableAlias, vc.getName(), colInfo);
cInfoLst.add(colInfo);
}
// 3.4 Build row type from field <type, name>
RelDataType rowType = TypeConverter.getType(cluster, rr, null);
// 4. Build RelOptAbstractTable
String fullyQualifiedTabName = tab.getDbName();
if (fullyQualifiedTabName != null && !fullyQualifiedTabName.isEmpty())
fullyQualifiedTabName = fullyQualifiedTabName + "." + tab.getTableName();
else
fullyQualifiedTabName = tab.getTableName();
RelOptHiveTable optTable = new RelOptHiveTable(relOptSchema, fullyQualifiedTabName,
tableAlias, rowType, tab, nonPartitionColumns, partitionColumns, conf, partitionCache,
noColsMissingStats);
// 5. Build Hive Table Scan Rel
tableRel = new HiveTableScanRel(cluster, cluster.traitSetOf(HiveRel.CONVENTION), optTable,
rowType);
// 6. Add Schema(RR) to RelNode-Schema map
ImmutableMap<String, Integer> hiveToOptiqColMap = buildHiveToOptiqColumnMap(rr, tableRel);
relToHiveRR.put(tableRel, rr);