public ProjectedColumn(PName name, PName familyName, int position, boolean nullable, ColumnRef sourceColumnRef, byte[] cq) { super(sourceColumnRef.getColumn()); this.name = name; this.familyName = familyName; this.position = position; this.nullable = nullable; this.sourceColumnRef = sourceColumnRef; this.cq = cq; }
@Override protected ColumnRef resolveColumn(ColumnParseNode node) throws SQLException { ColumnRef ref = super.resolveColumn(node); isColumnReferenced.set(ref.getColumn().getPosition()); return ref; } }
@Override public String getColumnDisplayName(ColumnRef ref, boolean schemaNameCaseSensitive, boolean colNameCaseSensitive) { return '"' + ref.getColumn().getName().getString() + '"'; } };
public void projectColumns(Scan scan) { assert(!isSubselect()); if (isWildCardSelect()) { scan.getFamilyMap().clear(); return; } for (ColumnRef columnRef : columnRefs.keySet()) { if (columnRef.getTableRef().equals(tableRef) && !SchemaUtil.isPKColumn(columnRef.getColumn()) && !(columnRef instanceof LocalIndexColumnRef)) { EncodedColumnsUtil.setColumns(columnRef.getColumn(), tableRef.getTable(), scan); } } }
@Override protected ColumnRef resolveColumn(ColumnParseNode node) throws SQLException { ColumnRef ref = super.resolveColumn(node); PTable table = ref.getTable(); // Track if we need to compare KeyValue during filter evaluation // using column family. If the column qualifier is enough, we // just use that. try { if (!SchemaUtil.isPKColumn(ref.getColumn())) { table.getColumnForColumnName(ref.getColumn().getName().getString()); } } catch (AmbiguousColumnException e) { disambiguateWithFamily = true; } return ref; } }
@Override public Expression visit(ColumnParseNode node) throws SQLException { ColumnRef ref = resolveColumn(node); TableRef tableRef = ref.getTableRef(); Expression newColumnExpression = ref.newColumnExpression(node.isTableNameCaseSensitive(), node.isCaseSensitive()); if (tableRef.equals(context.getCurrentTable()) && !SchemaUtil.isPKColumn(ref.getColumn())) { byte[] cq = tableRef.getTable().getImmutableStorageScheme() == ImmutableStorageScheme.SINGLE_CELL_ARRAY_WITH_OFFSETS ? QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES : ref.getColumn().getColumnQualifierBytes(); // track the where condition columns. Later we need to ensure the Scan in HRS scans these column CFs context.addWhereConditionColumn(ref.getColumn().getFamilyName().getBytes(), cq); } return newColumnExpression; }
public ColumnRef(TableRef tableRef, int columnPosition) { if (tableRef == null) { throw new NullPointerException(); } if (columnPosition < 0 || columnPosition >= tableRef.getTable().getColumns().size()) { throw new IllegalArgumentException("Column position of " + columnPosition + " must be between 0 and " + tableRef.getTable().getColumns().size() + " for table " + tableRef.getTable().getName().getString()); } this.tableRef = tableRef; this.columnPosition = columnPosition; PColumn column = getColumn(); int i = -1; if (SchemaUtil.isPKColumn(column)) { for (PColumn pkColumn : tableRef.getTable().getPKColumns()) { i++; if (pkColumn == column) { break; } } } pkSlotPosition = i; }
public PTable createProjectedTable(boolean retainPKColumns, StatementContext context) throws SQLException { assert(!isSubselect()); List<ColumnRef> sourceColumns = new ArrayList<ColumnRef>(); PTable table = tableRef.getTable(); if (retainPKColumns) { for (PColumn column : table.getPKColumns()) { sourceColumns.add(new ColumnRef(tableRef, column.getPosition())); } } if (isWildCardSelect()) { for (PColumn column : table.getColumns()) { if (!retainPKColumns || !SchemaUtil.isPKColumn(column)) { sourceColumns.add(new ColumnRef(tableRef, column.getPosition())); } } } else { for (Map.Entry<ColumnRef, ColumnRefType> e : columnRefs.entrySet()) { ColumnRef columnRef = e.getKey(); if (columnRef.getTableRef().equals(tableRef) && (!retainPKColumns || !SchemaUtil.isPKColumn(columnRef.getColumn()))) { if (columnRef instanceof LocalIndexColumnRef) { sourceColumns.add(new LocalIndexDataColumnRef(context, tableRef, IndexUtil.getIndexColumnName(columnRef.getColumn()))); } else { sourceColumns.add(columnRef); } } } } return TupleProjectionCompiler.createProjectedTable(tableRef, sourceColumns, retainPKColumns); }
try { ColumnRef ref = resolver.resolveColumn(this.getSchemaName(), this.getTableName(), this.getName()); PColumn column = ref.getColumn(); if (!SchemaUtil.isPKColumn(column)) { PTable table = ref.getTable();
@Override public Void visit(ColumnParseNode node) throws SQLException { try { ColumnRef resolveColumn = context.getResolver().resolveColumn(node.getSchemaName(), node.getTableName(), node.getName()); if (!SchemaUtil.isPKColumn(resolveColumn.getColumn())) { nonPkColumnRefSet.add(resolveColumn); } } catch (ColumnNotFoundException e) { if (context.getCurrentTable().getTable().getIndexType() == IndexType.LOCAL) { try { localIndexColumnRefSet.add(new LocalIndexDataColumnRef(context, context.getCurrentTable(), node.getName())); } catch (ColumnFamilyNotFoundException c) { throw e; } } else { throw e; } } return null; } }
public String getColumnDisplayName(ColumnRef ref, boolean cfCaseSensitive, boolean cqCaseSensitive) { String cf = null; String cq = null; PColumn column = ref.getColumn(); String name = column.getName().getString(); boolean isIndex = IndexUtil.isIndexColumn(name); if ((table.getType() == PTableType.PROJECTED && TupleProjectionCompiler.PROJECTED_TABLE_SCHEMA.equals(table.getSchemaName())) || table.getType() == PTableType.SUBQUERY) { cq = name; } else if (SchemaUtil.isPKColumn(column)) { cq = isIndex ? IndexUtil.getDataColumnName(name) : name; } else { String defaultFamilyName = table.getDefaultFamilyName() == null ? QueryConstants.DEFAULT_COLUMN_FAMILY : table.getDefaultFamilyName().getString(); // Translate to the data table column name String dataFamilyName = isIndex ? IndexUtil.getDataColumnFamilyName(name) : column.getFamilyName().getString() ; cf = (table.getIndexType()==IndexType.LOCAL? IndexUtil.getActualColumnFamilyName(defaultFamilyName):defaultFamilyName).equals(dataFamilyName) ? null : dataFamilyName; cq = isIndex ? IndexUtil.getDataColumnName(name) : name; } cf = (cf!=null && cfCaseSensitive) ? "\"" + cf + "\"" : cf; cq = cqCaseSensitive ? "\"" + cq + "\"" : cq; return SchemaUtil.getColumnDisplayName(cf, cq); }
String colName = ref.getColumn().getName().getString(); String tableAlias = tableRef.getTableAlias(); if (resolveColumn) {
PColumn columnToDrop = columnRef.getColumn(); tableColumnsToDrop.add(columnToDrop); if (SchemaUtil.isPKColumn(columnToDrop)) { byte[] emptyCF = getNewEmptyColumnFamilyOrNull(tableContainingColumnToDrop, columnRefToDrop.getColumn()); if (emptyCF != null) { try { PColumn droppedColumn = droppedColumnRef.getColumn(); MutationPlan plan = compiler.compile( Collections.singletonList(droppedColumnTableRef),
@Override public Expression visit(ColumnParseNode node) throws SQLException { ColumnRef ref = resolveColumn(node); TableRef tableRef = ref.getTableRef(); ImmutableBytesWritable ptr = context.getTempPtr(); PColumn column = ref.getColumn(); // If we have an UPDATABLE view, then we compile those view constants (i.e. columns in equality constraints // in the view) to constants. This allows the optimize to optimize out reference to them in various scenarios. // If the column is matched in a WHERE clause against a constant not equal to it's constant, then the entire // query would become degenerate. if (!resolveViewConstants && IndexUtil.getViewConstantValue(column, ptr)) { return LiteralExpression.newConstant(column.getDataType().toObject(ptr), column.getDataType()); } if (tableRef.equals(context.getCurrentTable()) && !SchemaUtil.isPKColumn(column)) { // project only kv columns addColumn(column); } Expression expression = ref.newColumnExpression(node.isTableNameCaseSensitive(), node.isCaseSensitive()); Expression wrappedExpression = wrapGroupByExpression(expression); // If we're in an aggregate expression // and we're not in the context of an aggregate function // and we didn't just wrap our column reference // then we're mixing aggregate and non aggregate expressions in the same expression. // This catches cases like this: SELECT sum(a_integer) + a_integer FROM atable GROUP BY a_string if (isAggregate && aggregateFunction == null && wrappedExpression == expression) { throwNonAggExpressionInAggException(expression.toString()); } return wrappedExpression; }
@Override public ParseNode visit(ColumnParseNode node) throws SQLException { ColumnRef dataColRef = getResolver().resolveColumn(node.getSchemaName(), node.getTableName(), node.getName()); PColumn dataCol = dataColRef.getColumn(); TableRef dataTableRef = dataColRef.getTableRef(); ParseNode indexColNode = new ColumnParseNode(tName, '"' + indexColName + '"', node.getAlias()); PDataType indexColType = IndexUtil.getIndexColumnDataType(dataCol); PDataType dataColType = dataColRef.getColumn().getDataType();
public Expression newColumnExpression(boolean schemaNameCaseSensitive, boolean colNameCaseSensitive) throws SQLException { PTable table = tableRef.getTable(); PColumn column = this.getColumn(); String displayName = tableRef.getColumnDisplayName(this, schemaNameCaseSensitive, colNameCaseSensitive); if (SchemaUtil.isPKColumn(column)) {
try { ref = new LocalIndexDataColumnRef(context, tableRef, indexColName); indexColumn = ref.getColumn(); } catch (ColumnFamilyNotFoundException c) { throw e;
try { ref = new LocalIndexDataColumnRef(context, tableRef, indexColName); indexColumn = ref.getColumn(); indexColumnFamily = indexColumn.getFamilyName() == null ? null
for (int i = retainPKColumns ? position : 0; i < sourceColumnRefs.size(); i++) { ColumnRef sourceColumnRef = sourceColumnRefs.get(i); PColumn sourceColumn = sourceColumnRef.getColumn(); String colName = sourceColumn.getName().getString(); String aliasedName = tableRef.getTableAlias() == null ?
int minPosition = (isSalted ? 1 : 0) + (isMultiTenant ? 1 : 0) + (isSharedViewIndex ? 1 : 0); if (pkPosition < minPosition) { throw new ColumnNotFoundException(table.getSchemaName().getString(), table.getTableName().getString(), null, ref.getColumn().getName().getString());