Java Code Examples for org.apache.phoenix.schema.PTable#newKey()
The following examples show how to use
org.apache.phoenix.schema.PTable#newKey() .
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: UpsertCompiler.java From phoenix with Apache License 2.0 | 6 votes |
private static void setValues(byte[][] values, int[] pkSlotIndex, int[] columnIndexes, PTable table, Map<ImmutableBytesPtr,Map<PColumn,byte[]>> mutation) { Map<PColumn,byte[]> columnValues = Maps.newHashMapWithExpectedSize(columnIndexes.length); byte[][] pkValues = new byte[table.getPKColumns().size()][]; // If the table uses salting, the first byte is the salting byte, set to an empty array // here and we will fill in the byte later in PRowImpl. if (table.getBucketNum() != null) { pkValues[0] = new byte[] {0}; } for (int i = 0; i < values.length; i++) { byte[] value = values[i]; PColumn column = table.getColumns().get(columnIndexes[i]); if (SchemaUtil.isPKColumn(column)) { pkValues[pkSlotIndex[i]] = value; } else { columnValues.put(column, value); } } ImmutableBytesPtr ptr = new ImmutableBytesPtr(); table.newKey(ptr, pkValues); mutation.put(ptr, columnValues); }
Example 2
Source File: SystemCatalogWALEntryFilterIT.java From phoenix with Apache License 2.0 | 5 votes |
public Get getGet(PTable catalogTable, byte[] tenantId, String viewName) { byte[][] tenantKeyParts = new byte[5][]; tenantKeyParts[0] = tenantId; tenantKeyParts[1] = Bytes.toBytes(SCHEMA_NAME.toUpperCase()); tenantKeyParts[2] = Bytes.toBytes(viewName.toUpperCase()); tenantKeyParts[3] = Bytes.toBytes(VIEW_COLUMN_NAME); tenantKeyParts[4] = VIEW_COLUMN_FAMILY_BYTES; ImmutableBytesWritable key = new ImmutableBytesWritable(); catalogTable.newKey(key, tenantKeyParts); //the backing byte array of key might have extra space at the end. // need to just slice "the good parts" which we do by calling copyBytes return new Get(key.copyBytes()); }
Example 3
Source File: UpsertCompiler.java From phoenix with Apache License 2.0 | 4 votes |
private static void setValues(byte[][] values, int[] pkSlotIndex, int[] columnIndexes, PTable table, MultiRowMutationState mutation, PhoenixStatement statement, boolean useServerTimestamp, IndexMaintainer maintainer, byte[][] viewConstants, byte[] onDupKeyBytes, int numSplColumns) throws SQLException { long columnValueSize = 0; Map<PColumn,byte[]> columnValues = Maps.newHashMapWithExpectedSize(columnIndexes.length); byte[][] pkValues = new byte[table.getPKColumns().size()][]; // If the table uses salting, the first byte is the salting byte, set to an empty array // here and we will fill in the byte later in PRowImpl. if (table.getBucketNum() != null) { pkValues[0] = new byte[] {0}; } for(int i = 0; i < numSplColumns; i++) { pkValues[i + (table.getBucketNum() != null ? 1 : 0)] = values[i]; } Long rowTimestamp = null; // case when the table doesn't have a row timestamp column RowTimestampColInfo rowTsColInfo = new RowTimestampColInfo(useServerTimestamp, rowTimestamp); for (int i = 0, j = numSplColumns; j < values.length; j++, i++) { byte[] value = values[j]; PColumn column = table.getColumns().get(columnIndexes[i]); if (SchemaUtil.isPKColumn(column)) { pkValues[pkSlotIndex[i]] = value; if (SchemaUtil.getPKPosition(table, column) == table.getRowTimestampColPos()) { if (!useServerTimestamp) { PColumn rowTimestampCol = table.getPKColumns().get(table.getRowTimestampColPos()); rowTimestamp = PLong.INSTANCE.getCodec().decodeLong(value, 0, rowTimestampCol.getSortOrder()); if (rowTimestamp < 0) { throw new IllegalDataException("Value of a column designated as ROW_TIMESTAMP cannot be less than zero"); } rowTsColInfo = new RowTimestampColInfo(useServerTimestamp, rowTimestamp); } } } else { columnValues.put(column, value); columnValueSize += (column.getEstimatedSize() + value.length); } } ImmutableBytesPtr ptr = new ImmutableBytesPtr(); table.newKey(ptr, pkValues); if (table.getIndexType() == IndexType.LOCAL && maintainer != null) { byte[] rowKey = maintainer.buildDataRowKey(ptr, viewConstants); HRegionLocation region = statement.getConnection().getQueryServices() .getTableRegionLocation(table.getParentName().getBytes(), rowKey); byte[] regionPrefix = region.getRegion().getStartKey().length == 0 ? new byte[region .getRegion().getEndKey().length] : region.getRegion() .getStartKey(); if (regionPrefix.length != 0) { ptr.set(ScanRanges.prefixKey(ptr.get(), 0, ptr.getLength(), regionPrefix, regionPrefix.length)); } } mutation.put(ptr, new RowMutationState(columnValues, columnValueSize, statement.getConnection().getStatementExecutionCounter(), rowTsColInfo, onDupKeyBytes)); }