public Schema getTableSchema(KuduTableHandle tableHandle) { KuduTable table = tableHandle.getTable(this); return table.getSchema(); }
private PartialRow buildPrimaryKey() { Schema schema = table.getSchema(); PartialRow row = new PartialRow(schema); RowHelper.copyPrimaryKey(schema, currentRow, row); return row; } }
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 RangeBoundValue buildRangePartitionBound(KuduTable table, byte[] rangeKey) { if (rangeKey.length == 0) { return null; } else { Schema schema = table.getSchema(); PartitionSchema partitionSchema = table.getPartitionSchema(); PartitionSchema.RangeSchema rangeSchema = partitionSchema.getRangeSchema(); List<Integer> rangeColumns = rangeSchema.getColumns(); final int numColumns = rangeColumns.size(); PartialRow bound = KeyEncoderAccessor.decodeRangePartitionKey(schema, partitionSchema, rangeKey); ArrayList<Object> list = new ArrayList<>(); for (int i = 0; i < numColumns; i++) { Object obj = toValue(schema, bound, rangeColumns.get(i)); list.add(obj); } return new RangeBoundValue(list); } }
protected Upsert upsertRecordToKudu(KuduTable kuduTable, Record record, List<String> fieldNames) throws IllegalStateException, Exception { Upsert upsert = kuduTable.newUpsert(); this.buildPartialRow(kuduTable.getSchema(), upsert.getRow(), record, fieldNames); return upsert; }
final int primaryKeyColumnCount = table.getSchema().getPrimaryKeyColumnCount(); KuduScanToken.KuduScanTokenBuilder builder = client.newScanTokenBuilder(table);
protected Insert insertRecordToKudu(KuduTable kuduTable, Record record, List<String> fieldNames) throws IllegalStateException, Exception { Insert insert = kuduTable.newInsert(); this.buildPartialRow(kuduTable.getSchema(), insert.getRow(), record, fieldNames); return insert; }
Schema schema = table.getSchema();
@Override public Table getTable(String name) { KuduScanSpec scanSpec = new KuduScanSpec(name); try { KuduTable table = plugin.getClient().openTable(name); Schema schema = table.getSchema(); return new DrillKuduTable(getName(), plugin, schema, scanSpec); } catch (Exception e) { logger.warn("Failure while retrieving kudu table {}", name, e); return null; } }
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; }
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; }
@Override public void init() throws DBException { this.tableName = getProperties().getProperty(TABLENAME_PROPERTY, TABLENAME_PROPERTY_DEFAULT); initClient(); this.session = client.newSession(); if (getProperties().getProperty(SYNC_OPS_OPT) != null && getProperties().getProperty(SYNC_OPS_OPT).equals("false")) { this.session.setFlushMode(KuduSession.FlushMode.AUTO_FLUSH_BACKGROUND); this.session.setMutationBufferSpace( getIntFromProp(getProperties(), BUFFER_NUM_OPS_OPT, BUFFER_NUM_OPS_DEFAULT)); } else { this.session.setFlushMode(KuduSession.FlushMode.AUTO_FLUSH_SYNC); } try { this.kuduTable = client.openTable(tableName); this.schema = kuduTable.getSchema(); } catch (Exception e) { throw new DBException("Could not open a table because of:", e); } }
@Override public void deleteRows(Block rowIds) { Schema schema = table.getSchema(); KuduSession session = clientSession.newSession(); session.setFlushMode(FlushMode.AUTO_FLUSH_BACKGROUND); try { try { for (int i = 0; i < rowIds.getPositionCount(); i++) { int len = rowIds.getSliceLength(i); Slice slice = rowIds.getSlice(i, 0, len); PartialRow row = KeyEncoderAccessor.decodePrimaryKey(schema, slice.getBytes()); Delete delete = table.newDelete(); RowHelper.copyPrimaryKey(schema, row, delete.getRow()); session.apply(delete); } } finally { session.close(); } } catch (KuduException e) { throw new RuntimeException(e); } }
String rawName = schemaEmulation.toRawName(schemaTableName); KuduTable table = client.openTable(rawName); Schema schema = table.getSchema(); PartitionDesign design = KuduTableProperties.getPartitionDesign(table); RangePartitionDefinition definition = design.getRange();
Schema schema = table.getSchema(); for (TupleDomain.ColumnDomain<ColumnHandle> columnDomain : constraintSummary.getColumnDomains().get()) { int position = ((KuduColumnHandle) columnDomain.getColumn()).getOrdinalPosition();
AlterTableOptions alterTableOptions = new AlterTableOptions(); AtomicBoolean updated = new AtomicBoolean(false); Schema schema = table.getSchema();
@Override public Schema getTableSchema(KuduTableHandle tableHandle) { KuduTable table = tableHandle.getTable(this); return table.getSchema(); }
private PartialRow buildPrimaryKey() { Schema schema = table.getSchema(); PartialRow row = new PartialRow(schema); RowHelper.copyPrimaryKey(schema, currentRow, row); return row; } }
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); }