Java Code Examples for org.apache.phoenix.schema.PTable#getColumn()
The following examples show how to use
org.apache.phoenix.schema.PTable#getColumn() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WhereCompiler.java From phoenix with Apache License 2.0 | 6 votes |
@Override protected ColumnRef resolveColumn(ColumnParseNode node) throws SQLException { ColumnRef ref = super.resolveColumn(node); PTable table = ref.getTable(); // if current table in the context is local index and table in column reference is global means // the column is not present in the local index. If where condition contains the column // not present in the index then we need to go through main table for each row in index and get the // missing column which is like full scan of index table and data table. Which is // inefficient. Then we can skip this plan. if (context.getCurrentTable().getTable().getIndexType() == IndexType.LOCAL && (table.getIndexType() == null || table.getIndexType() == IndexType.GLOBAL)) { throw new ColumnNotFoundException(ref.getColumn().getName().getString()); } // 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.getColumn(ref.getColumn().getName().getString()); } } catch (AmbiguousColumnException e) { disambiguateWithFamily = true; } return ref; }
Example 2
Source File: PhoenixRuntime.java From phoenix with Apache License 2.0 | 6 votes |
/** * Returns the column info for the given column for the given table. * * @param table * @param columnName User-specified column name. May be family-qualified or bare. * @return columnInfo associated with the column in the table * @throws SQLException if parameters are null or if column is not found or if column is ambiguous. */ public static ColumnInfo getColumnInfo(PTable table, String columnName) throws SQLException { if (table==null) { throw new SQLException("Table must not be null."); } if (columnName==null) { throw new SQLException("columnName must not be null."); } PColumn pColumn = null; if (columnName.contains(QueryConstants.NAME_SEPARATOR)) { String[] tokens = columnName.split(QueryConstants.NAME_SEPARATOR_REGEX); if (tokens.length!=2) { throw new SQLException(String.format("Unable to process column %s, expected family-qualified name.",columnName)); } String familyName = tokens[0]; String familyColumn = tokens[1]; PColumnFamily family = table.getColumnFamily(familyName); pColumn = family.getColumn(familyColumn); } else { pColumn = table.getColumn(columnName); } return getColumnInfo(pColumn); }
Example 3
Source File: PhoenixRuntime.java From phoenix with Apache License 2.0 | 6 votes |
private static PColumn getPColumn(PTable table, @Nullable String familyName, String columnName) throws SQLException { if (table==null) { throw new SQLException("Table must not be null."); } if (columnName==null) { throw new SQLException("columnName must not be null."); } // normalize and remove quotes from family and column names before looking up. familyName = SchemaUtil.normalizeIdentifier(familyName); columnName = SchemaUtil.normalizeIdentifier(columnName); PColumn pColumn = null; if (familyName != null) { PColumnFamily family = table.getColumnFamily(familyName); pColumn = family.getColumn(columnName); } else { pColumn = table.getColumn(columnName); } return pColumn; }
Example 4
Source File: ProjectionCompiler.java From phoenix with Apache License 2.0 | 5 votes |
private static void projectIndexColumnFamily(StatementContext context, String cfName, TableRef tableRef, List<Expression> projectedExpressions, List<ExpressionProjector> projectedColumns) throws SQLException { PTable index = tableRef.getTable(); PhoenixConnection conn = context.getConnection(); String tableName = index.getParentName().getString(); PTable table = conn.getMetaDataCache().getTable(new PTableKey(conn.getTenantId(), tableName)); PColumnFamily pfamily = table.getColumnFamily(cfName); for (PColumn column : pfamily.getColumns()) { String indexColName = IndexUtil.getIndexColumnName(column); PColumn indexColumn = null; ColumnRef ref = null; try { indexColumn = index.getColumn(indexColName); ref = new ColumnRef(tableRef, indexColumn.getPosition()); } catch (ColumnNotFoundException e) { if (index.getIndexType() == IndexType.LOCAL) { try { ref = new LocalIndexDataColumnRef(context, indexColName); indexColumn = ref.getColumn(); } catch (ColumnFamilyNotFoundException c) { throw e; } } else { throw e; } } Expression expression = ref.newColumnExpression(); projectedExpressions.add(expression); String colName = column.getName().toString(); boolean isCaseSensitive = !SchemaUtil.normalizeIdentifier(colName).equals(colName); projectedColumns.add(new ExpressionProjector(colName, tableRef.getTableAlias() == null ? table.getName().getString() : tableRef.getTableAlias(), expression, isCaseSensitive)); } }