Java Code Examples for org.apache.phoenix.schema.PColumn#getColumnQualifierBytes()
The following examples show how to use
org.apache.phoenix.schema.PColumn#getColumnQualifierBytes() .
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: FromCompiler.java From phoenix with Apache License 2.0 | 6 votes |
public static ColumnResolver getResolverForCompiledDerivedTable(PhoenixConnection connection, TableRef tableRef, RowProjector projector) throws SQLException { List<PColumn> projectedColumns = new ArrayList<PColumn>(); PTable table = tableRef.getTable(); for (PColumn column : table.getColumns()) { Expression sourceExpression = projector.getColumnProjector(column.getPosition()).getExpression(); PColumnImpl projectedColumn = new PColumnImpl(column.getName(), column.getFamilyName(), sourceExpression.getDataType(), sourceExpression.getMaxLength(), sourceExpression.getScale(), sourceExpression.isNullable(), column.getPosition(), sourceExpression.getSortOrder(), column.getArraySize(), column.getViewConstant(), column.isViewReferenced(), column.getExpressionStr(), column.isRowTimestamp(), column.isDynamic(), column.getColumnQualifierBytes(), column.getTimestamp()); projectedColumns.add(projectedColumn); } PTable t = PTableImpl.builderWithColumns(table, projectedColumns) .build(); return new SingleTableColumnResolver(connection, new TableRef(tableRef.getTableAlias(), t, tableRef.getLowerBoundTimeStamp(), tableRef.hasDynamicCols())); }
Example 2
Source File: KeyValueColumnExpression.java From phoenix with Apache License 2.0 | 5 votes |
public KeyValueColumnExpression(PColumn column) { super(column); this.cf = column.getFamilyName().getBytes(); // for backward compatibility since older tables won't have columnQualifierBytes in their metadata this.cq = column.getColumnQualifierBytes() != null ? column.getColumnQualifierBytes() : column.getName().getBytes(); this.displayName = column.getName().getString(); }
Example 3
Source File: KeyValueColumnExpression.java From phoenix with Apache License 2.0 | 5 votes |
public KeyValueColumnExpression(PColumn column, String displayName) { super(column); this.cf = column.getFamilyName().getBytes(); // for backward compatibility since older tables won't have columnQualifierBytes in their metadata this.cq = column.getColumnQualifierBytes() != null ? column.getColumnQualifierBytes() : column.getName().getBytes(); this.displayName = displayName; }
Example 4
Source File: EncodedColumnsUtil.java From phoenix with Apache License 2.0 | 5 votes |
public static void setColumns(PColumn column, PTable table, Scan scan) { if (table.getImmutableStorageScheme() == ImmutableStorageScheme.SINGLE_CELL_ARRAY_WITH_OFFSETS) { // if a table storage scheme is COLUMNS_STORED_IN_SINGLE_CELL set then all columns of a column family are stored in a single cell // (with the qualifier name being same as the family name), just project the column family here // so that we can calculate estimatedByteSize correctly in ProjectionCompiler scan.addFamily(column.getFamilyName().getBytes()); } else { if (column.getColumnQualifierBytes() != null) { scan.addColumn(column.getFamilyName().getBytes(), column.getColumnQualifierBytes()); } } }
Example 5
Source File: TupleProjectionCompiler.java From phoenix with Apache License 2.0 | 4 votes |
public static PTable createProjectedTable(TableRef tableRef, List<ColumnRef> sourceColumnRefs, boolean retainPKColumns) throws SQLException { PTable table = tableRef.getTable(); List<PColumn> projectedColumns = new ArrayList<PColumn>(); int position = table.getBucketNum() != null ? 1 : 0; 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 ? SchemaUtil.getColumnName(table.getName().getString(), colName) : SchemaUtil.getColumnName(tableRef.getTableAlias(), colName); PName familyName = SchemaUtil.isPKColumn(sourceColumn) ? (retainPKColumns ? null : PNameFactory.newName(VALUE_COLUMN_FAMILY)) : sourceColumn.getFamilyName(); // If we're not retaining the PK columns, then we should switch columns to be nullable PColumn column = new ProjectedColumn(PNameFactory.newName(aliasedName), familyName, position++, sourceColumn.isNullable(), sourceColumnRef, sourceColumn.getColumnQualifierBytes()); projectedColumns.add(column); } EncodedCQCounter cqCounter = EncodedCQCounter.NULL_COUNTER; if (EncodedColumnsUtil.usesEncodedColumnNames(table)) { cqCounter = EncodedCQCounter.copy(table.getEncodedCQCounter()); } return new PTableImpl.Builder() .setType(PTableType.PROJECTED) .setTimeStamp(table.getTimeStamp()) .setIndexDisableTimestamp(table.getIndexDisableTimestamp()) .setSequenceNumber(table.getSequenceNumber()) .setImmutableRows(table.isImmutableRows()) .setDisableWAL(table.isWALDisabled()) .setMultiTenant(table.isMultiTenant()) .setStoreNulls(table.getStoreNulls()) .setViewType(table.getViewType()) .setViewIndexIdType(table.getviewIndexIdType()) .setViewIndexId(table.getViewIndexId()) .setTransactionProvider(table.getTransactionProvider()) .setUpdateCacheFrequency(table.getUpdateCacheFrequency()) .setNamespaceMapped(table.isNamespaceMapped()) .setAutoPartitionSeqName(table.getAutoPartitionSeqName()) .setAppendOnlySchema(table.isAppendOnlySchema()) .setImmutableStorageScheme(table.getImmutableStorageScheme()) .setQualifierEncodingScheme(table.getEncodingScheme()) .setBaseColumnCount(BASE_TABLE_BASE_COLUMN_COUNT) .setEncodedCQCounter(cqCounter) .setUseStatsForParallelization(table.useStatsForParallelization()) .setExcludedColumns(ImmutableList.of()) .setTenantId(table.getTenantId()) .setSchemaName(PROJECTED_TABLE_SCHEMA) .setTableName(table.getTableName()) .setPkName(table.getPKName()) .setRowKeyOrderOptimizable(table.rowKeyOrderOptimizable()) .setBucketNum(table.getBucketNum()) .setIndexes(Collections.emptyList()) .setPhysicalNames(ImmutableList.of()) .setColumns(projectedColumns) .build(); }
Example 6
Source File: StoreNullsIT.java From phoenix with Apache License 2.0 | 4 votes |
private void ensureNullsStoredCorrectly(Connection conn) throws Exception { ResultSet rs1 = conn.createStatement().executeQuery("SELECT NAME FROM "+dataTableName); rs1.next(); assertEquals("v1", rs1.getString(1)); rs1.next(); assertNull(rs1.getString(1)); rs1.next(); Table htable = ConnectionFactory.createConnection(getUtility().getConfiguration()).getTable( TableName.valueOf(dataTableName)); Scan s = new Scan(); s.setRaw(true); ResultScanner scanner = htable.getScanner(s); // first row has a value for name Result rs = scanner.next(); PTable table = conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, dataTableName)); PColumn nameColumn = table.getColumnForColumnName("NAME"); byte[] qualifier = table.getImmutableStorageScheme()== ImmutableStorageScheme.SINGLE_CELL_ARRAY_WITH_OFFSETS ? QueryConstants.SINGLE_KEYVALUE_COLUMN_QUALIFIER_BYTES : nameColumn.getColumnQualifierBytes(); assertTrue(rs.containsColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, qualifier)); assertTrue(rs.size() == 2); // 2 because it also includes the empty key value column KeyValueColumnExpression colExpression = table.getImmutableStorageScheme() == ImmutableStorageScheme.SINGLE_CELL_ARRAY_WITH_OFFSETS ? new SingleCellColumnExpression(nameColumn, "NAME", table.getEncodingScheme(), table.getImmutableStorageScheme()) : new KeyValueColumnExpression(nameColumn); ImmutableBytesPtr ptr = new ImmutableBytesPtr(); colExpression.evaluate(new ResultTuple(rs), ptr); assertEquals(new ImmutableBytesPtr(PVarchar.INSTANCE.toBytes("v1")), ptr); rs = scanner.next(); if ( !mutable && !columnEncoded // we don't issue a put with empty value for immutable tables with cols stored per key value || (mutable && !storeNulls)) { // for this case we use a delete to represent the null assertFalse(rs.containsColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, qualifier)); assertEquals(1, rs.size()); } else { assertTrue(rs.containsColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, qualifier)); assertEquals(2, rs.size()); } // assert null stored correctly ptr = new ImmutableBytesPtr(); if (colExpression.evaluate(new ResultTuple(rs), ptr)) { assertEquals(new ImmutableBytesPtr(ByteUtil.EMPTY_BYTE_ARRAY), ptr); } assertNull(scanner.next()); scanner.close(); htable.close(); }