use of org.apache.phoenix.schema.PColumn in project phoenix by apache.
the class IndexStatementRewriter method visit.
@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();
// view constants if based on an UPDATABLE view
if (dataCol.getViewConstant() != null) {
byte[] viewConstant = dataCol.getViewConstant();
// Ignore last byte, as it's only there so we can have a way to differentiate null
// from the absence of a value.
ptr.set(viewConstant, 0, viewConstant.length - 1);
Object literal = dataCol.getDataType().toObject(ptr);
return new LiteralParseNode(literal, dataCol.getDataType());
}
TableName tName = getReplacedTableName(dataTableRef);
if (multiTableRewriteMap != null && tName == null)
return node;
String indexColName = IndexUtil.getIndexColumnName(dataCol);
ParseNode indexColNode = new ColumnParseNode(tName, '"' + indexColName + '"', node.getAlias());
PDataType indexColType = IndexUtil.getIndexColumnDataType(dataCol);
PDataType dataColType = dataColRef.getColumn().getDataType();
// TODO: test case for this
if (!isTopLevel() && indexColType != dataColType) {
indexColNode = FACTORY.cast(indexColNode, dataColType, null, null);
}
return indexColNode;
}
use of org.apache.phoenix.schema.PColumn in project phoenix by apache.
the class JoinCompiler method joinProjectedTables.
public static PTable joinProjectedTables(PTable left, PTable right, JoinType type) throws SQLException {
Preconditions.checkArgument(left.getType() == PTableType.PROJECTED);
Preconditions.checkArgument(right.getType() == PTableType.PROJECTED);
List<PColumn> merged = Lists.<PColumn>newArrayList();
if (type == JoinType.Full) {
for (PColumn c : left.getColumns()) {
merged.add(new ProjectedColumn(c.getName(), c.getFamilyName(), c.getPosition(), true, ((ProjectedColumn) c).getSourceColumnRef(), SchemaUtil.isPKColumn(c) ? null : c.getName().getBytes()));
}
} else {
merged.addAll(left.getColumns());
}
int position = merged.size();
for (PColumn c : right.getColumns()) {
if (!SchemaUtil.isPKColumn(c)) {
PColumn column = new ProjectedColumn(c.getName(), c.getFamilyName(), position++, type == JoinType.Inner ? c.isNullable() : true, ((ProjectedColumn) c).getSourceColumnRef(), c.getName().getBytes());
merged.add(column);
}
}
if (left.getBucketNum() != null) {
merged.remove(0);
}
return PTableImpl.makePTable(left.getTenantId(), left.getSchemaName(), PNameFactory.newName(SchemaUtil.getTableName(left.getName().getString(), right.getName().getString())), left.getType(), left.getIndexState(), left.getTimeStamp(), left.getSequenceNumber(), left.getPKName(), left.getBucketNum(), merged, left.getParentSchemaName(), left.getParentTableName(), left.getIndexes(), left.isImmutableRows(), Collections.<PName>emptyList(), null, null, PTable.DEFAULT_DISABLE_WAL, left.isMultiTenant(), left.getStoreNulls(), left.getViewType(), left.getViewIndexId(), left.getIndexType(), left.rowKeyOrderOptimizable(), left.isTransactional(), left.getUpdateCacheFrequency(), left.getIndexDisableTimestamp(), left.isNamespaceMapped(), left.getAutoPartitionSeqName(), left.isAppendOnlySchema(), ONE_CELL_PER_COLUMN, NON_ENCODED_QUALIFIERS, PTable.EncodedCQCounter.NULL_COUNTER, left.useStatsForParallelization());
}
use of org.apache.phoenix.schema.PColumn in project phoenix by apache.
the class IndexHalfStoreFileReaderGenerator method getViewConstants.
private byte[][] getViewConstants(PTable dataTable) {
int dataPosOffset = (dataTable.getBucketNum() != null ? 1 : 0) + (dataTable.isMultiTenant() ? 1 : 0);
byte[][] viewConstants = null;
int nViewConstants = 0;
if (dataTable.getType() == PTableType.VIEW) {
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
List<PColumn> dataPkColumns = dataTable.getPKColumns();
for (int i = dataPosOffset; i < dataPkColumns.size(); i++) {
PColumn dataPKColumn = dataPkColumns.get(i);
if (dataPKColumn.getViewConstant() != null) {
nViewConstants++;
}
}
if (nViewConstants > 0) {
viewConstants = new byte[nViewConstants][];
int j = 0;
for (int i = dataPosOffset; i < dataPkColumns.size(); i++) {
PColumn dataPkColumn = dataPkColumns.get(i);
if (dataPkColumn.getViewConstant() != null) {
if (IndexUtil.getViewConstantValue(dataPkColumn, ptr)) {
viewConstants[j++] = ByteUtil.copyKeyBytesIfNecessary(ptr);
} else {
throw new IllegalStateException();
}
}
}
}
}
return viewConstants;
}
use of org.apache.phoenix.schema.PColumn in project phoenix by apache.
the class CorrelatePlanTest method createProjectedTableFromLiterals.
private TableRef createProjectedTableFromLiterals(Object[] row) {
List<PColumn> columns = Lists.<PColumn>newArrayList();
for (int i = 0; i < row.length; i++) {
String name = ParseNodeFactory.createTempAlias();
Expression expr = LiteralExpression.newConstant(row[i]);
PName colName = PNameFactory.newName(name);
columns.add(new PColumnImpl(PNameFactory.newName(name), PNameFactory.newName(VALUE_COLUMN_FAMILY), expr.getDataType(), expr.getMaxLength(), expr.getScale(), expr.isNullable(), i, expr.getSortOrder(), null, null, false, name, false, false, colName.getBytes()));
}
try {
PTable pTable = PTableImpl.makePTable(null, PName.EMPTY_NAME, PName.EMPTY_NAME, PTableType.SUBQUERY, null, MetaDataProtocol.MIN_TABLE_TIMESTAMP, PTable.INITIAL_SEQ_NUM, null, null, columns, null, null, Collections.<PTable>emptyList(), false, Collections.<PName>emptyList(), null, null, false, false, false, null, null, null, true, false, 0, 0L, Boolean.FALSE, null, false, ImmutableStorageScheme.ONE_CELL_PER_COLUMN, QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, EncodedCQCounter.NULL_COUNTER, true);
TableRef sourceTable = new TableRef(pTable);
List<ColumnRef> sourceColumnRefs = Lists.<ColumnRef>newArrayList();
for (PColumn column : sourceTable.getTable().getColumns()) {
sourceColumnRefs.add(new ColumnRef(sourceTable, column.getPosition()));
}
return new TableRef(TupleProjectionCompiler.createProjectedTable(sourceTable, sourceColumnRefs, false));
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.apache.phoenix.schema.PColumn in project phoenix by apache.
the class LiteralResultIteratorPlanTest method testLiteralResultIteratorPlan.
private void testLiteralResultIteratorPlan(Object[][] expectedResult, Integer offset, Integer limit) throws SQLException {
QueryPlan plan = newLiteralResultIterationPlan(offset, limit);
ResultIterator iter = plan.iterator();
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
for (Object[] row : expectedResult) {
Tuple next = iter.next();
assertNotNull(next);
for (int i = 0; i < row.length; i++) {
PColumn column = table.getColumns().get(i);
boolean eval = new ProjectedColumnExpression(column, table, column.getName().getString()).evaluate(next, ptr);
Object o = eval ? column.getDataType().toObject(ptr) : null;
assertEquals(row[i], o);
}
}
assertNull(iter.next());
}
Aggregations