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); }
/** * Calculate what the new column family will be after the column is dropped, returning null * if unchanged. * @param table table containing column to drop * @param columnToDrop column being dropped * @return the new column family or null if unchanged. */ private static byte[] getNewEmptyColumnFamilyOrNull (PTable table, PColumn columnToDrop) { if (table.getType() != PTableType.VIEW && !SchemaUtil.isPKColumn(columnToDrop) && table.getColumnFamilies().get(0).getName().equals(columnToDrop.getFamilyName()) && table.getColumnFamilies().get(0).getColumns().size() == 1) { return SchemaUtil.getEmptyColumnFamily(table.getColumnFamilies().subList(1, table.getColumnFamilies().size())); } // If unchanged, return null return null; }
@Override protected ColumnRef resolveColumn(ColumnParseNode node) throws SQLException { ColumnRef ref = super.resolveColumn(node); // If we encounter any non PK column, then we can't aggregate on-the-fly // because the distinct groups have no correlation to the KV column value if (!SchemaUtil.isPKColumn(ref.getColumn())) { orderPreserving = OrderPreserving.NO; } if (columnRef == null) { columnRef = ref; } else if (!columnRef.equals(ref)) { // If we encounter more than one column reference in an expression, // we can't assume the result of the expression will be key ordered. // For example GROUP BY a * b orderPreserving = OrderPreserving.NO; } return ref; }
private static KeyValueSchema buildSchema(PTable table) { KeyValueSchemaBuilder builder = new KeyValueSchemaBuilder(0); for (PColumn column : table.getColumns()) { if (!SchemaUtil.isPKColumn(column)) { builder.addField(column); } } return builder.build(); }
private static KeyValueSchema buildSchema(PTable table) { KeyValueSchemaBuilder builder = new KeyValueSchemaBuilder(0); if (table != null) { for (PColumn column : table.getColumns()) { if (!SchemaUtil.isPKColumn(column)) { builder.addField(column); } } } return builder.build(); }
public static String getIndexColumnName(PColumn dataColumn) { String dataColumnFamilyName = SchemaUtil.isPKColumn(dataColumn) ? null : dataColumn.getFamilyName().getString(); return getIndexColumnName(dataColumnFamilyName, dataColumn.getName().getString()); }
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 void projectColumns(Scan scan, TableRef table) { if (isWildCardSelect(select)) { scan.getFamilyMap().clear(); return; } for (ColumnRef columnRef : columnRefs.keySet()) { if (columnRef.getTableRef().equals(table) && !SchemaUtil.isPKColumn(columnRef.getColumn())) { scan.addColumn(columnRef.getColumn().getFamilyName().getBytes(), columnRef.getColumn().getName().getBytes()); } } }
public ScanProjector(ProjectedPTableWrapper projected) { List<PColumn> columns = projected.getTable().getColumns(); expressions = new Expression[columns.size() - projected.getTable().getPKColumns().size()]; // we do not count minNullableIndex for we might do later merge. KeyValueSchemaBuilder builder = new KeyValueSchemaBuilder(0); int i = 0; for (PColumn column : projected.getTable().getColumns()) { if (!SchemaUtil.isPKColumn(column)) { builder.addField(column); expressions[i++] = projected.getSourceExpression(column); } } schema = builder.build(); valueSet = ValueBitSet.newInstance(schema); }
@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.getColumn(ref.getColumn().getName().getString()); } } catch (AmbiguousColumnException e) { disambiguateWithFamily = true; } return ref; } }
if (!retainPKColumns || !SchemaUtil.isPKColumn(column)) { addProjectedColumn(projectedColumns, sourceExpressions, columnNameMap, column, tableRef, PNameFactory.newName(ScanProjector.VALUE_COLUMN_FAMILY), hasSaltingColumn); if (e.getValue() != ColumnRefType.PREFILTER && columnRef.getTableRef().equals(tableRef) && (!retainPKColumns || !SchemaUtil.isPKColumn(columnRef.getColumn()))) { PColumn column = columnRef.getColumn(); addProjectedColumn(projectedColumns, sourceExpressions, columnNameMap,
int indexPos = i - indexPosOffset; PColumn column = IndexUtil.getDataColumn(dataTable, indexColumn.getName().getString()); boolean isPKColumn = SchemaUtil.isPKColumn(column); if (isPKColumn) { int dataPkPos = dataTable.getPKColumns().indexOf(column) - (dataTable.getBucketNum() == null ? 0 : 1);
byte[] indexKey = SchemaUtil.getTableKey(tenantId, index.getSchemaName().getBytes(), index.getTableName().getBytes()); if (SchemaUtil.isPKColumn(indexColumn)) {
@Override public Expression visit(ColumnParseNode node) throws SQLException { ColumnRef ref = resolveColumn(node); TableRef tableRef = ref.getTableRef(); if (tableRef.equals(context.getCurrentTable()) && !SchemaUtil.isPKColumn(ref.getColumn())) { // project only kv columns context.getScan().addColumn(ref.getColumn().getFamilyName().getBytes(), ref.getColumn().getName().getBytes()); } Expression expression = ref.newColumnExpression(); 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; }
public static PTableWrapper mergeProjectedTables(PTableWrapper lWrapper, PTableWrapper rWrapper, boolean innerJoin) throws SQLException { PTable left = lWrapper.getTable(); PTable right = rWrapper.getTable(); List<PColumn> merged = new ArrayList<PColumn>(); merged.addAll(left.getColumns()); int position = merged.size(); for (PColumn c : right.getColumns()) { if (!SchemaUtil.isPKColumn(c)) { PColumnImpl column = new PColumnImpl(c.getName(), PNameFactory.newName(ScanProjector.VALUE_COLUMN_FAMILY), c.getDataType(), c.getMaxLength(), c.getScale(), innerJoin ? c.isNullable() : true, position++, c.getColumnModifier()); merged.add(column); } } if (left.getBucketNum() != null) { merged.remove(0); } PTable t = PTableImpl.makePTable(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.getParentTableName(), left.getIndexes(), left.isImmutableRows(), null, null, null, null, PTable.DEFAULT_DISABLE_WAL, left.isMultiTenant(), left.getViewType()); ListMultimap<String, String> mergedMap = ArrayListMultimap.<String, String>create(); mergedMap.putAll(lWrapper.getColumnNameMap()); mergedMap.putAll(rWrapper.getColumnNameMap()); return new PTableWrapper(t, mergedMap); }
PColumn columnToDrop = columnRef.getColumn(); tableColumnsToDrop.add(columnToDrop); if (SchemaUtil.isPKColumn(columnToDrop)) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_DROP_PK) .setColumnName(columnToDrop.getName().getString()).build().buildException(); try { PColumn indexColumn = index.getColumn(indexColumnName); if (SchemaUtil.isPKColumn(indexColumn)) { indexesToDrop.add(new TableRef(index)); } else {
if (SchemaUtil.isPKColumn(column)) { && SchemaUtil.isPKColumn(column) && pkColumnsNames.size() > 1 && column.getPosition() < pkColumnsNames.size() - 1) {
if (SchemaUtil.isPKColumn(col)) { if (!unusedPkColumns.contains(col)) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.COLUMN_EXIST_IN_DEF).build().buildException(); throw new SQLExceptionInfo.Builder(SQLExceptionCode.COLUMN_EXIST_IN_DEF).build().buildException(); if (!SchemaUtil.isPKColumn(col)) {
coerceDataValueToIndexValue(dataColumn, indexColumn, ptr); indexValues[indexPKColumns.indexOf(indexColumn)-indexOffset] = ptr.copyBytes(); if (!SchemaUtil.isPKColumn(indexColumn)) { indexValuesSet.set(indexColumn.getPosition()-nIndexColumns-indexOffset);
public ColumnExpression newColumnExpression() { boolean isIndex = tableRef.getTable().getType() == PTableType.INDEX; if (SchemaUtil.isPKColumn(this.getColumn())) { String name = this.getColumn().getName().getString(); if (isIndex) { name = IndexUtil.getDataColumnName(name); } return new RowKeyColumnExpression( getColumn(), new RowKeyValueAccessor(this.getTable().getPKColumns(), pkSlotPosition), name); } if (isIndex) return new IndexKeyValueColumnExpression(getColumn()); if (tableRef.getTable().getType() == PTableType.JOIN) return new ProjectedColumnExpression(getColumn(), tableRef.getTable()); return new KeyValueColumnExpression(getColumn()); }