private ConnectorTableMetadata getTableMetadata(KuduTableHandle tableHandle) { KuduTable table = tableHandle.getTable(clientSession); Schema schema = table.getSchema(); List<ColumnMetadata> columnsMetaList = schema.getColumns().stream() .filter(column -> !column.isKey() || !column.getName().equals(KuduColumnHandle.ROW_ID)) .map(this::getColumnMetadata) .collect(toImmutableList()); Map<String, Object> properties = clientSession.getTableProperties(tableHandle); return new ConnectorTableMetadata(tableHandle.getSchemaTableName(), columnsMetaList, properties); }
@Override public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle connectorTableHandle) { KuduTableHandle tableHandle = (KuduTableHandle) connectorTableHandle; KuduTable table = tableHandle.getTable(clientSession); Schema schema = table.getSchema(); List<ColumnSchema> columns = schema.getColumns(); List<Type> columnTypes = columns.stream() .map(TypeHelper::fromKuduColumn).collect(toImmutableList()); return new KuduInsertTableHandle( connectorId, tableHandle.getSchemaTableName(), columnTypes, table); }
List<ColumnSchema> columns = schema.getColumns(); List<Type> columnTypes = columns.stream() .map(TypeHelper::fromKuduColumn).collect(toImmutableList());
public static PartitionDesign getPartitionDesign(KuduTable table) { Schema schema = table.getSchema(); PartitionDesign partitionDesign = new PartitionDesign(); PartitionSchema partitionSchema = table.getPartitionSchema(); List<HashPartitionDefinition> hashPartitions = partitionSchema.getHashBucketSchemas().stream() .map(hashBucketSchema -> { HashPartitionDefinition hash = new HashPartitionDefinition(); List<String> cols = hashBucketSchema.getColumnIds().stream() .map(idx -> schema.getColumnByIndex(idx).getName()).collect(toImmutableList()); hash.setColumns(cols); hash.setBuckets(hashBucketSchema.getNumBuckets()); return hash; }).collect(toImmutableList()); partitionDesign.setHash(hashPartitions); List<Integer> rangeColumns = partitionSchema.getRangeSchema().getColumns(); if (!rangeColumns.isEmpty()) { RangePartitionDefinition definition = new RangePartitionDefinition(); definition.setColumns(rangeColumns.stream() .map(i -> schema.getColumns().get(i).getName()) .collect(ImmutableList.toImmutableList())); partitionDesign.setRange(definition); } return partitionDesign; }
@Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { List<String> names = Lists.newArrayList(); List<RelDataType> types = Lists.newArrayList(); for (ColumnSchema column : schema.getColumns()) { names.add(column.getName()); RelDataType type = getSqlTypeFromKuduType(typeFactory, column.getType()); type = typeFactory.createTypeWithNullability(type, column.isNullable()); types.add(type); } return typeFactory.createStructType(types, names); }
private static LinkedHashMap<String, ColumnDesign> getColumns(KuduTable table) { Schema schema = table.getSchema(); LinkedHashMap<String, ColumnDesign> columns = new LinkedHashMap<>(); for (ColumnSchema columnSchema : schema.getColumns()) { ColumnDesign design = new ColumnDesign(); design.setNullable(columnSchema.isNullable()); design.setPrimaryKey(columnSchema.isKey()); design.setCompression(lookupCompressionString(columnSchema.getCompressionAlgorithm())); design.setEncoding(lookupEncodingString(columnSchema.getEncoding())); columns.put(columnSchema.getName(), design); } return columns; }
for (ColumnSchema columnSchema : schema.getColumns())
private void setNull(ColumnSchema column) { assert nullsBitSet != null; checkNotFrozen(); checkColumnExists(column); if (!column.isNullable()) { throw new IllegalArgumentException(column.getName() + " cannot be set to null"); } int idx = schema.getColumns().indexOf(column); columnsBitSet.set(idx); nullsBitSet.set(idx); }
private ConnectorTableMetadata getTableMetadata(KuduTableHandle tableHandle) { KuduTable table = tableHandle.getTable(clientSession); Schema schema = table.getSchema(); List<ColumnMetadata> columnsMetaList = schema.getColumns().stream() .filter(column -> !column.isKey() || !column.getName().equals(KuduColumnHandle.ROW_ID)) .map(this::getColumnMetadata) .collect(toImmutableList()); Map<String, Object> properties = clientSession.getTableProperties(tableHandle); return new ConnectorTableMetadata(tableHandle.getSchemaTableName(), columnsMetaList, properties); }
@Override public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle connectorTableHandle) { KuduTableHandle tableHandle = (KuduTableHandle) connectorTableHandle; KuduTable table = tableHandle.getTable(clientSession); Schema schema = table.getSchema(); List<ColumnSchema> columns = schema.getColumns(); List<Type> columnTypes = columns.stream() .map(TypeHelper::fromKuduColumn).collect(toImmutableList()); return new KuduInsertTableHandle( connectorId, tableHandle.getSchemaTableName(), columnTypes, table); }
private static LinkedHashMap<String, ColumnDesign> getColumns(KuduTable table) { Schema schema = table.getSchema(); LinkedHashMap<String, ColumnDesign> columns = new LinkedHashMap<>(); for (ColumnSchema columnSchema : schema.getColumns()) { ColumnDesign design = new ColumnDesign(); design.setNullable(columnSchema.isNullable()); design.setPrimaryKey(columnSchema.isKey()); design.setCompression(lookupCompressionString(columnSchema.getCompressionAlgorithm())); design.setEncoding(lookupEncodingString(columnSchema.getEncoding())); columns.put(columnSchema.getName(), design); } return columns; }
private void buildScannerAndCheckColumnsCount(AsyncKuduScanner.AsyncKuduScannerBuilder builder, int count) throws Exception { AsyncKuduScanner scanner = builder.build(); scanner.nextRows().join(DEFAULT_SLEEP); RowResultIterator rri = scanner.nextRows().join(DEFAULT_SLEEP); assertEquals(count, rri.next().getSchema().getColumns().size()); }
@Test public void testGetMissingColumnIndex() { PartialRow partialRow = getPartialRowWithAllTypes(); for (ColumnSchema columnSchema : partialRow.getSchema().getColumns()) { try { callGetByIndex(partialRow, 999, columnSchema.getType()); fail("Expected IndexOutOfBoundsException for type: " + columnSchema.getType()); } catch (IndexOutOfBoundsException ex) { // This is the expected exception. } } }
@Test public void testAddMissingColumnName() { PartialRow partialRow = getPartialRowWithAllTypes(); for (ColumnSchema columnSchema : partialRow.getSchema().getColumns()) { try { callAddByName(partialRow, "not-a-column", columnSchema.getType()); fail("Expected IllegalArgumentException for type: " + columnSchema.getType()); } catch (IllegalArgumentException ex) { // This is the expected exception. } } }
@Test public void testAddMissingColumnIndex() { PartialRow partialRow = getPartialRowWithAllTypes(); for (ColumnSchema columnSchema : partialRow.getSchema().getColumns()) { try { callAddByIndex(partialRow, 999, columnSchema.getType()); fail("Expected IndexOutOfBoundsException for type: " + columnSchema.getType()); } catch (IndexOutOfBoundsException ex) { // This is the expected exception. } } }
@Test public void testGetMissingColumnName() { PartialRow partialRow = getPartialRowWithAllTypes(); for (ColumnSchema columnSchema : partialRow.getSchema().getColumns()) { try { callGetByName(partialRow, "not-a-column", columnSchema.getType()); fail("Expected IllegalArgumentException for type: " + columnSchema.getType()); } catch (IllegalArgumentException ex) { // This is the expected exception. } } }
@Test public void testGetWrongTypeColumn() { PartialRow partialRow = getPartialRowWithAllTypes(); for (ColumnSchema columnSchema : partialRow.getSchema().getColumns()) { try { callGetByName(partialRow, columnSchema.getName(), getShiftedType(columnSchema.getType())); fail("Expected IllegalArgumentException for type: " + columnSchema.getType()); } catch (IllegalArgumentException ex) { // This is the expected exception. } } }
@Test public void testAddWrongTypeColumn() { PartialRow partialRow = getPartialRowWithAllTypes(); for (ColumnSchema columnSchema : partialRow.getSchema().getColumns()) { try { callAddByName(partialRow, columnSchema.getName(), getShiftedType(columnSchema.getType())); fail("Expected IllegalArgumentException for type: " + columnSchema.getType()); } catch (IllegalArgumentException ex) { // This is the expected exception. } } }
@Test public void testAddToFrozenRow() { PartialRow partialRow = getPartialRowWithAllTypes(); partialRow.freeze(); for (ColumnSchema columnSchema : partialRow.getSchema().getColumns()) { try { callAddByName(partialRow, columnSchema.getName(), columnSchema.getType()); fail("Expected IllegalStateException for type: " + columnSchema.getType()); } catch (IllegalStateException ex) { // This is the expected exception. } } }
@Test public void testGetUnsetColumn() { Schema schema = getSchemaWithAllTypes(); PartialRow partialRow = schema.newPartialRow(); for (ColumnSchema columnSchema : schema.getColumns()) { assertFalse(partialRow.isSet("null")); assertFalse(partialRow.isNull("null")); try { callGetByName(partialRow, columnSchema.getName(), columnSchema.getType()); fail("Expected IllegalArgumentException for type: " + columnSchema.getType()); } catch (IllegalArgumentException ex) { // This is the expected exception. } } }