/** * Verifies that the index schema only index columns for columns that are available * @param indices A mapping of the index details, not null * @param columns A mapping of column details, not null * @throws NullPointerException Thrown if the indices or columns container is null * @throws IllegalArgumentException Thrown if a {@link IndexSchema} indexes * a column that is not an available column */ public static void isValidIndexSchema(final Collection<IndexSchema> indices, final Collection<ColumnSchema> columns) { checkNotNull(indices); checkNotNull(columns); Set<String> columnNames = Sets.newHashSet(); for (ColumnSchema column : columns) { columnNames.add(column.getColumnName()); } for (final IndexSchema index : indices) { for (final String column : index.getColumns()) { if (!columnNames.contains(column)) { throw new IllegalArgumentException("Only columns in the table may be indexed."); } } } } }
/** * Retrieve from a list of indices which ones have been changed. * * @param indices Table indices * @param oldRecords Old MySQL row * @param newRecords New MySQL row * @return List of changed indices */ public static ImmutableList<IndexSchema> getChangedIndices(Collection<IndexSchema> indices, Map<String, ByteBuffer> oldRecords, Map<String, ByteBuffer> newRecords) { if (indices.isEmpty()) { return ImmutableList.of(); } MapDifference<String, ByteBuffer> diff = Maps.difference(oldRecords, newRecords); Set<String> changedColumns = Sets.difference( Sets.union(newRecords.keySet(), oldRecords.keySet()), diff.entriesInCommon().keySet()); ImmutableList.Builder<IndexSchema> changedIndices = ImmutableList.builder(); for (IndexSchema index : indices) { Set<String> indexColumns = ImmutableSet.copyOf(index.getColumns()); if (!Sets.intersection(changedColumns, indexColumns).isEmpty()) { changedIndices.add(index); } } return changedIndices.build(); }
/** * Set the values of the index row based on a sql row. If an index column is * missing from the sql row it is replaced with an explicit null. (This * method is intended for insert) * * @param row SQL row * @param indexName Columns in the index * @param tableSchema Table schema * @return The current builder instance */ public IndexRowKeyBuilder withRow(Row row, String indexName, TableSchema tableSchema) { checkNotNull(row, "row must not be null."); Map<String, ByteBuffer> recordCopy = Maps.newHashMap(row.getRecords()); for (String column : tableSchema.getIndexSchema(indexName).getColumns()) { if (!recordCopy.containsKey(column)) { recordCopy.put(column, null); } } this.fields = recordCopy; this.indexName = indexName; this.tableSchema = tableSchema; return this; }
List<byte[]> encodedRecords = Lists.newArrayList(); if (fields != null) { for (String column : tableSchema.getIndexSchema(indexName).getColumns()) { if (!fields.containsKey(column)) { continue;
if (!next.getUUID().equals(row.getUUID())) { for (String column : indexSchema.getColumns()) { boolean isNullInRecord = !row.getRecords().containsKey(column); if (isNullInRecord) {