private IndexMaintainer(RowKeySchema dataRowKeySchema, boolean isDataTableSalted, byte[] indexTableName, int nIndexColumns, int nIndexPKColumns, Integer nIndexSaltBuckets, List<PColumnFamily> cfs, boolean indexWALDisabled) { this(dataRowKeySchema, isDataTableSalted); int nDataPKColumns = dataRowKeySchema.getFieldCount() - (isDataTableSalted ? 1 : 0); this.indexTableName = indexTableName; this.indexedColumns = Sets.newLinkedHashSetWithExpectedSize(nIndexPKColumns-nDataPKColumns); this.indexedColumnTypes = Lists.<PDataType>newArrayListWithExpectedSize(nIndexPKColumns-nDataPKColumns); this.indexedColumnByteSizes = Lists.<Integer>newArrayListWithExpectedSize(nIndexPKColumns-nDataPKColumns); this.coveredColumns = Sets.newLinkedHashSetWithExpectedSize(nIndexColumns-nIndexPKColumns); this.allColumns = Sets.newLinkedHashSetWithExpectedSize(nDataPKColumns + nIndexColumns); this.allColumns.addAll(indexedColumns); this.allColumns.addAll(coveredColumns); this.rowKeyMetaData = newRowKeyMetaData(nIndexPKColumns); this.nIndexSaltBuckets = nIndexSaltBuckets == null ? 0 : nIndexSaltBuckets; this.dataEmptyKeyValueCF = SchemaUtil.getEmptyColumnFamily(cfs); this.nDataCFs = cfs.size(); this.indexWALDisabled = indexWALDisabled; }
/** * 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; }
private static boolean isEmptyKeyValue(PTable table, ColumnReference ref) { byte[] emptyKeyValueCF = SchemaUtil.getEmptyColumnFamily(table.getColumnFamilies()); return (Bytes.compareTo(emptyKeyValueCF, ref.getFamily()) == 0 && Bytes.compareTo(QueryConstants.EMPTY_COLUMN_BYTES, ref.getQualifier()) == 0); }
protected PTable addDynamicColumns(List<ColumnDef> dynColumns, PTable theTable) throws SQLException { if (!dynColumns.isEmpty()) { List<PColumn> allcolumns = new ArrayList<PColumn>(); allcolumns.addAll(theTable.getColumns()); int position = allcolumns.size(); PName defaultFamilyName = PNameFactory.newName(SchemaUtil.getEmptyColumnFamily(theTable.getColumnFamilies())); for (ColumnDef dynColumn : dynColumns) { PName familyName = defaultFamilyName; PName name = PNameFactory.newName(dynColumn.getColumnDefName().getColumnName()); String family = dynColumn.getColumnDefName().getFamilyName(); if (family != null) { theTable.getColumnFamily(family); // Verifies that column family exists familyName = PNameFactory.newName(family); } allcolumns.add(new PColumnImpl(name, familyName, dynColumn.getDataType(), dynColumn.getMaxLength(), dynColumn.getScale(), dynColumn.isNull(), position, dynColumn.getColumnModifier())); position++; } theTable = PTableImpl.makePTable(theTable, allcolumns); } return theTable; } }
public ParallelIterators(StatementContext context, TableRef tableRef, FilterableStatement statement, RowProjector projector, GroupBy groupBy, Integer limit, ParallelIteratorFactory iteratorFactory) throws SQLException { super(context, tableRef, groupBy); this.splits = getSplits(context, tableRef, statement.getHint()); this.iteratorFactory = iteratorFactory; Scan scan = context.getScan(); PTable table = tableRef.getTable(); if (projector.isProjectEmptyKeyValue()) { Map<byte [], NavigableSet<byte []>> familyMap = scan.getFamilyMap(); // If nothing projected into scan and we only have one column family, just allow everything // to be projected and use a FirstKeyOnlyFilter to skip from row to row. This turns out to // be quite a bit faster. if (familyMap.isEmpty() && table.getColumnFamilies().size() == 1) { // Project the one column family. We must project a column family since it's possible // that there are other non declared column families that we need to ignore. scan.addFamily(table.getColumnFamilies().get(0).getName().getBytes()); ScanUtil.andFilterAtBeginning(scan, new FirstKeyOnlyFilter()); } else { byte[] ecf = SchemaUtil.getEmptyColumnFamily(table.getColumnFamilies()); // Project empty key value unless the column family containing it has // been projected in its entirety. if (!familyMap.containsKey(ecf) || familyMap.get(ecf) != null) { scan.addColumn(ecf, QueryConstants.EMPTY_COLUMN_BYTES); } } } if (limit != null) { ScanUtil.andFilterAtEnd(scan, new PageFilter(limit)); } }
public MutationState createTable(CreateTableStatement statement, byte[][] splits, PTable parent, Expression viewExpression, ViewType viewType) throws SQLException { PTable table = createTableInternal(statement, splits, parent, viewExpression, viewType); if (table == null || table.getType() == PTableType.VIEW) { return new MutationState(0,connection); } // Hack to get around the case when an SCN is specified on the connection. // In this case, we won't see the table we just created yet, so we hack // around it by forcing the compiler to not resolve anything. PostDDLCompiler compiler = new PostDDLCompiler(connection); //connection.setAutoCommit(true); // Execute any necessary data updates Long scn = connection.getSCN(); long ts = (scn == null ? table.getTimeStamp() : scn); // Getting the schema through the current connection doesn't work when the connection has an scn specified // Since the table won't be added to the current connection. TableRef tableRef = new TableRef(null, table, ts, false); byte[] emptyCF = SchemaUtil.getEmptyColumnFamily(table.getColumnFamilies()); MutationPlan plan = compiler.compile(Collections.singletonList(tableRef), emptyCF, null, null, tableRef.getTimeStamp()); return connection.getQueryServices().updateData(plan); }
} catch (ColumnFamilyNotFoundException e) { projectCF = family.getFirst(); emptyCF = SchemaUtil.getEmptyColumnFamily(table.getColumnFamilies());
byte[] essentialCF = table.getType() == PTableType.VIEW ? ByteUtil.EMPTY_BYTE_ARRAY : SchemaUtil.getEmptyColumnFamily(table.getColumnFamilies()); filter = new RowKeyComparisonFilter(whereClause, essentialCF); break;