public ProjectedPTableWrapper createProjectedTable(TableRef tableRef, boolean retainPKColumns) throws SQLException {
List<PColumn> projectedColumns = new ArrayList<PColumn>();
List<Expression> sourceExpressions = new ArrayList<Expression>();
ListMultimap<String, String> columnNameMap = ArrayListMultimap.<String, String>create();
PTable table = tableRef.getTable();
boolean hasSaltingColumn = retainPKColumns && table.getBucketNum() != null;
if (retainPKColumns) {
for (PColumn column : table.getPKColumns()) {
addProjectedColumn(projectedColumns, sourceExpressions, columnNameMap,
column, tableRef, column.getFamilyName(), hasSaltingColumn);
}
}
if (isWildCardSelect(select)) {
for (PColumn column : table.getColumns()) {
if (!retainPKColumns || !SchemaUtil.isPKColumn(column)) {
addProjectedColumn(projectedColumns, sourceExpressions, columnNameMap,
column, tableRef, PNameFactory.newName(ScanProjector.VALUE_COLUMN_FAMILY), hasSaltingColumn);
}
}
} else {
for (Map.Entry<ColumnRef, ColumnRefType> e : columnRefs.entrySet()) {
ColumnRef columnRef = e.getKey();
if (e.getValue() != ColumnRefType.PREFILTER
&& columnRef.getTableRef().equals(tableRef)
&& (!retainPKColumns || !SchemaUtil.isPKColumn(columnRef.getColumn()))) {
PColumn column = columnRef.getColumn();
addProjectedColumn(projectedColumns, sourceExpressions, columnNameMap,
column, tableRef, PNameFactory.newName(ScanProjector.VALUE_COLUMN_FAMILY), hasSaltingColumn);
}
}
}
PTable t = PTableImpl.makePTable(PNameFactory.newName(PROJECTED_TABLE_SCHEMA), table.getName(), PTableType.JOIN, table.getIndexState(),
table.getTimeStamp(), table.getSequenceNumber(), table.getPKName(), retainPKColumns ? table.getBucketNum() : null,
projectedColumns, table.getParentTableName(), table.getIndexes(),
table.isImmutableRows(), table.getBaseSchemaName(), null, null, null, table.isWALDisabled(), table.isMultiTenant(), table.getViewType());
return new ProjectedPTableWrapper(t, columnNameMap, sourceExpressions);
}