org.apache.kudu.ColumnSchema Java Examples
The following examples show how to use
org.apache.kudu.ColumnSchema.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KuduScanCustomizerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Ignore public void testBeforeConsumer() throws Exception { final Map<String, Object> options = new HashMap<>(); customizer.customize(getComponent(), options); final KuduTable table = connection.openTable("impala::default.syndesis_todo"); final List<String> projectColumns = new ArrayList<>(1); final Iterator<ColumnSchema> columns = table.getSchema().getColumns().iterator(); while (columns.hasNext()) { projectColumns.add(columns.next().getName()); } final KuduScanner scanner = connection.newScannerBuilder(table) .setProjectedColumnNames(projectColumns) .build(); final Exchange inbound = new DefaultExchange(createCamelContext()); inbound.getIn().setBody(scanner); getComponent().getBeforeConsumer().process(inbound); }
Example #2
Source File: KuduFilterInfo.java From bahir-flink with Apache License 2.0 | 6 votes |
public KuduPredicate toPredicate(ColumnSchema column) { KuduPredicate predicate; switch (this.type) { case IS_IN: predicate = KuduPredicate.newInListPredicate(column, (List<?>) this.value); break; case IS_NULL: predicate = KuduPredicate.newIsNullPredicate(column); break; case IS_NOT_NULL: predicate = KuduPredicate.newIsNotNullPredicate(column); break; default: predicate = predicateComparator(column); break; } return predicate; }
Example #3
Source File: KuduFilterInfo.java From flink-learning with Apache License 2.0 | 6 votes |
public KuduPredicate toPredicate(ColumnSchema column) { KuduPredicate predicate; switch (this.type) { case IS_IN: predicate = KuduPredicate.newInListPredicate(column, (List<?>) this.value); break; case IS_NULL: predicate = KuduPredicate.newIsNullPredicate(column); break; case IS_NOT_NULL: predicate = KuduPredicate.newIsNotNullPredicate(column); break; default: predicate = predicateComparator(column); break; } return predicate; }
Example #4
Source File: KuduFilterInfo.java From flink-learning with Apache License 2.0 | 6 votes |
public KuduPredicate toPredicate(ColumnSchema column) { KuduPredicate predicate; switch (this.type) { case IS_IN: predicate = KuduPredicate.newInListPredicate(column, (List<?>) this.value); break; case IS_NULL: predicate = KuduPredicate.newIsNullPredicate(column); break; case IS_NOT_NULL: predicate = KuduPredicate.newIsNotNullPredicate(column); break; default: predicate = predicateComparator(column); break; } return predicate; }
Example #5
Source File: KuduResource.java From camel-quarkus with Apache License 2.0 | 6 votes |
@Path("/createTable") @PUT public Response createTable() { LOG.info("Calling createTable"); final List<ColumnSchema> columns = new ArrayList<>(2); columns.add(new ColumnSchema.ColumnSchemaBuilder("id", Type.STRING).key(true).build()); columns.add(new ColumnSchema.ColumnSchemaBuilder("name", Type.STRING).build()); CreateTableOptions cto = new CreateTableOptions().setRangePartitionColumns(Arrays.asList("id")).setNumReplicas(1); final Map<String, Object> headers = new HashMap<>(); headers.put(KuduConstants.CAMEL_KUDU_SCHEMA, new Schema(columns)); headers.put(KuduConstants.CAMEL_KUDU_TABLE_OPTIONS, cto); producerTemplate.requestBodyAndHeaders("direct:create_table", null, headers); return Response.ok().build(); }
Example #6
Source File: KuduTableProperties.java From presto-kudu with Apache License 2.0 | 6 votes |
public static PartialRow toRangeBoundToPartialRow(Schema schema, RangePartitionDefinition definition, RangeBoundValue boundValue) { PartialRow partialRow = new PartialRow(schema); if (boundValue != null) { List<Integer> rangeColumns = definition.getColumns().stream() .map(name -> schema.getColumnIndex(name)).collect(toImmutableList()); if (rangeColumns.size() != boundValue.getValues().size()) { throw new IllegalStateException("Expected " + rangeColumns.size() + " range columns, but got " + boundValue.getValues().size()); } for (int i = 0; i < rangeColumns.size(); i++) { Object obj = boundValue.getValues().get(i); int idx = rangeColumns.get(i); ColumnSchema columnSchema = schema.getColumnByIndex(idx); setColumnValue(partialRow, idx, obj, columnSchema.getType(), columnSchema.getName()); } } return partialRow; }
Example #7
Source File: KuduPartitionScannerCallableTest.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
@KuduClusterTestContext(kuduClusterBasedTest = true) @Test public void testSettersForPojo() throws Exception { initOperatorState(); AbstractKuduPartitionScanner<UnitTestTablePojo,InputOperatorControlTuple> currentScanner = unitTestStepwiseScanInputOperator.getScanner(); SQLToKuduPredicatesTranslator translator = new SQLToKuduPredicatesTranslator( "select introwkey as intColumn from unittests", new ArrayList<ColumnSchema>(columnDefs.values())); List<KuduPartitionScanAssignmentMeta> scansForThisQuery = currentScanner.preparePlanForScanners(translator); KuduPartitionScannerCallable<UnitTestTablePojo,InputOperatorControlTuple> threadToScan = new KuduPartitionScannerCallable<>(unitTestStepwiseScanInputOperator,scansForThisQuery.get(0), currentScanner.getConnectionPoolForThreads().get(0), unitTestStepwiseScanInputOperator.extractSettersForResultObject(translator),translator); long countOfScan = threadToScan.call(); }
Example #8
Source File: KuduOperations.java From geowave with Apache License 2.0 | 6 votes |
@Override public MetadataWriter createMetadataWriter(final MetadataType metadataType) { synchronized (CREATE_TABLE_MUTEX) { try { if (!metadataExists(metadataType)) { final List<ColumnSchema> columns = new ArrayList<>(); for (final KuduMetadataField f : KuduMetadataField.values()) { f.addColumn(columns); } client.createTable( getKuduQualifiedName(getMetadataTableName(metadataType)), new Schema(columns), new CreateTableOptions().addHashPartitions( Collections.singletonList(KuduMetadataField.GW_PRIMARY_ID_KEY.getFieldName()), KuduUtils.KUDU_DEFAULT_BUCKETS).setNumReplicas(KuduUtils.KUDU_DEFAULT_REPLICAS)); } } catch (final IOException e) { LOGGER.error( "Unable to create metadata table '{}'", getKuduQualifiedName(getMetadataTableName(metadataType)), e); } } return new KuduMetadataWriter(this, metadataType); }
Example #9
Source File: NativeKuduClientSession.java From presto-kudu with Apache License 2.0 | 6 votes |
private void createAndFillSchemasTable() throws KuduException { List<String> existingSchemaNames = listSchemaNamesFromTablets(); ColumnSchema tenantColumnSchema = new ColumnSchema.ColumnSchemaBuilder("tenant", Type.STRING) .key(true).build(); ColumnSchema schemaColumnSchema = new ColumnSchema.ColumnSchemaBuilder("schema", Type.STRING) .key(true).build(); Schema schema = new Schema(ImmutableList.of(tenantColumnSchema, schemaColumnSchema)); CreateTableOptions options = new CreateTableOptions(); options.setNumReplicas(1); // TODO config options.addHashPartitions(ImmutableList.of(tenantColumnSchema.getName()), 2); KuduTable schemasTable = client.createTable(rawSchemasTableName, schema, options); KuduSession session = client.newSession(); session.setFlushMode(SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND); try { for (String schemaName : existingSchemaNames) { Insert insert = schemasTable.newInsert(); fillSchemaRow(insert.getRow(), schemaName); session.apply(insert); } } finally { session.close(); } }
Example #10
Source File: AbstractKuduInputOperator.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
/** * Scans the metadata for the kudu table that this operator is scanning for and * returns back the mapping for the kudu column name to the ColumnSchema metadata definition. * Note that the Kudu columns names are case sensitive. * @return A Map with Kudu column names as keys and value as the Column Definition. * @throws Exception */ private Map<String,ColumnSchema> buildColumnSchemaForTable() throws Exception { if (kuduColNameToSchemaMapping == null) { ApexKuduConnection connectionForMetaDataScan = apexKuduConnectionInfo.build(); KuduTable table = connectionForMetaDataScan.getKuduTable(); List<ColumnSchema> tableColumns = table.getSchema().getColumns(); connectionForMetaDataScan.close(); Map<String,ColumnSchema> columnSchemaMap = new HashMap<>(); for (ColumnSchema aColumn: tableColumns) { columnSchemaMap.put(aColumn.getName(),aColumn); } kuduColNameToSchemaMapping = columnSchemaMap; } return kuduColNameToSchemaMapping; }
Example #11
Source File: KuduMetadata.java From presto-kudu with Apache License 2.0 | 6 votes |
@Override public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle connectorTableHandle) { KuduTableHandle tableHandle = fromConnectorTableHandle(session, connectorTableHandle); KuduTable table = tableHandle.getTable(clientSession); Schema schema = table.getSchema(); List<ColumnSchema> columns = schema.getColumns(); List<String> columnNames = columns.stream().map(ColumnSchema::getName).collect(toImmutableList()); List<Type> columnTypes = columns.stream() .map(TypeHelper::fromKuduColumn).collect(toImmutableList()); return new KuduInsertTableHandle( connectorId, tableHandle.getSchemaTableName(), columnNames, columnTypes, table); }
Example #12
Source File: AbstractKuduInputPartitioner.java From attic-apex-malhar with Apache License 2.0 | 6 votes |
/** * Builds a set of scan tokens. The list of scan tokens are generated as if the entire table is being scanned * i.e. a SELECT * FROM TABLE equivalent expression. This list is used to assign the partition pie assignments * for all of the planned partition of operators. Each operator gets a part of the PIE as if all columns were * selected. Subsequently when a query is to be processed, the query is used to generate the scan tokens applicable * for that query. Given that partition pie represents the entire data set, the scan assignments for the current * query will be a subset. * @return The list of scan tokens as if the entire table is getting scanned. * @throws Exception in cases when the connection to kudu cluster cannot be closed. */ public List<KuduScanToken> getKuduScanTokensForSelectAllColumns() throws Exception { // We are not using the current query for deciding the partition strategy but a SELECT * as // we do not want to want to optimize on just the current query. This prevents rapid throttling of operator // instances when the scan patterns are erratic. On the other hand, this might result on under utilized // operator resources in the DAG but will be consistent at a minimum. ApexKuduConnection apexKuduConnection = prototypeKuduInputOperator.getApexKuduConnectionInfo().build(); KuduClient clientHandle = apexKuduConnection.getKuduClient(); KuduTable table = apexKuduConnection.getKuduTable(); KuduScanToken.KuduScanTokenBuilder builder = clientHandle.newScanTokenBuilder(table); List<String> allColumns = new ArrayList<>(); List<ColumnSchema> columnList = apexKuduConnection.getKuduTable().getSchema().getColumns(); for ( ColumnSchema column : columnList) { allColumns.add(column.getName()); } builder.setProjectedColumnNames(allColumns); LOG.debug("Building the partition pie assignments for the input operator"); List<KuduScanToken> allPossibleTokens = builder.build(); apexKuduConnection.close(); return allPossibleTokens; }
Example #13
Source File: KuduConsumerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Ignore public void insertRow() throws KuduException, InterruptedException { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); assertMockEndpointsSatisfied(); List<Exchange> exchanges = mock.getReceivedExchanges(); assertEquals(1, exchanges.size()); KuduScanner scanner = exchanges.get(0).getIn().getBody(KuduScanner.class); RowResultIterator results = scanner.nextRows(); RowResult result = results.next(); ColumnSchema columnByIndex = result.getSchema().getColumnByIndex(0); String name = columnByIndex.getName(); assertEquals("id", name); assertEquals(46, result.getInt(0)); assertEquals(10, result.getInt(1)); }
Example #14
Source File: AbstractKuduTest.java From syndesis with Apache License 2.0 | 6 votes |
protected void createTestTable(final String tableName, final String connection) throws KuduException { try (KuduClient client = new KuduClient.KuduClientBuilder(connection).build()) { final List<ColumnSchema> columns = new ArrayList<>(5); final List<String> columnNames = Arrays.asList("id", "title", "name", "lastname", "address"); for (int i = 0; i < columnNames.size(); i++) { final Type type = i == 0 ? Type.INT32 : Type.STRING; columns.add( new ColumnSchema.ColumnSchemaBuilder(columnNames.get(i), type) .key(i == 0) .build()); } final List<String> rangeKeys = new ArrayList<>(); rangeKeys.add("id"); client.createTable(tableName, new Schema(columns), new CreateTableOptions().setRangePartitionColumns(rangeKeys)); } }
Example #15
Source File: KuduTableProperties.java From presto with Apache License 2.0 | 6 votes |
public static PartialRow toRangeBoundToPartialRow(Schema schema, RangePartitionDefinition definition, RangeBoundValue boundValue) { PartialRow partialRow = new PartialRow(schema); if (boundValue != null) { List<Integer> rangeColumns = definition.getColumns().stream() .map(schema::getColumnIndex).collect(toImmutableList()); if (rangeColumns.size() != boundValue.getValues().size()) { throw new IllegalStateException("Expected " + rangeColumns.size() + " range columns, but got " + boundValue.getValues().size()); } for (int i = 0; i < rangeColumns.size(); i++) { Object obj = boundValue.getValues().get(i); int idx = rangeColumns.get(i); ColumnSchema columnSchema = schema.getColumnByIndex(idx); setColumnValue(partialRow, idx, obj, columnSchema.getType(), columnSchema.getName()); } } return partialRow; }
Example #16
Source File: KuduTableProperties.java From presto with Apache License 2.0 | 6 votes |
public static ColumnSchema.CompressionAlgorithm lookupCompression(String compression) { switch (compression.toLowerCase(Locale.ENGLISH)) { case "default": case "default_compression": return ColumnSchema.CompressionAlgorithm.DEFAULT_COMPRESSION; case "no": case "no_compression": return ColumnSchema.CompressionAlgorithm.NO_COMPRESSION; case "lz4": return ColumnSchema.CompressionAlgorithm.LZ4; case "snappy": return ColumnSchema.CompressionAlgorithm.SNAPPY; case "zlib": return ColumnSchema.CompressionAlgorithm.ZLIB; default: throw new IllegalArgumentException(); } }
Example #17
Source File: KuduTableProperties.java From presto with Apache License 2.0 | 6 votes |
public static String lookupCompressionString(ColumnSchema.CompressionAlgorithm algorithm) { switch (algorithm) { case DEFAULT_COMPRESSION: return "default"; case NO_COMPRESSION: return "no"; case LZ4: return "lz4"; case SNAPPY: return "snappy"; case ZLIB: return "zlib"; default: return "unknown"; } }
Example #18
Source File: KuduCreateTableCustomizer.java From syndesis with Apache License 2.0 | 6 votes |
private void beforeProducer(Exchange exchange) { final Message in = exchange.getIn(); final KuduTable model = exchange.getIn().getBody(KuduTable.class); if (model != null && ObjectHelper.isNotEmpty(model.getSchema())) { schema = model.getSchema(); } KuduTable.ColumnSchema[] columnSchema = schema.getColumns(); List<ColumnSchema> columns = new ArrayList<>(columnSchema.length); List<String> rangeKeys = new ArrayList<>(); for (int i = 0; i < columnSchema.length; i++) { if (columnSchema[i].isKey()) { rangeKeys.add(columnSchema[i].getName()); } columns.add( new ColumnSchema.ColumnSchemaBuilder(columnSchema[i].getName(), convertType(columnSchema[i].getType())) .key(columnSchema[i].isKey()) .build() ); } in.setHeader("Schema", new Schema(columns)); in.setHeader("TableOptions", new CreateTableOptions().setRangePartitionColumns(rangeKeys)); }
Example #19
Source File: KuduTableProperties.java From presto with Apache License 2.0 | 6 votes |
public static String lookupEncodingString(ColumnSchema.Encoding encoding) { switch (encoding) { case AUTO_ENCODING: return "auto"; case BIT_SHUFFLE: return "bitshuffle"; case DICT_ENCODING: return "dictionary"; case PLAIN_ENCODING: return "plain"; case PREFIX_ENCODING: return "prefix"; case RLE: return "runlength"; case GROUP_VARINT: return "group_varint"; default: return "unknown"; } }
Example #20
Source File: KuduCreateTableCustomizer.java From syndesis with Apache License 2.0 | 6 votes |
private void setOptions(Map<String, Object> options) { if (options == null) { return; } if (!options.isEmpty()) { String[] columns = ConnectorOptions.extractOptionAndMap(options, "columns", names -> names.split(";", -1), new String[]{}); KuduTable.ColumnSchema[] columnSchemas = new KuduTable.ColumnSchema[columns.length]; for (int i = 0; i < columns.length; i++) { String[] column = columns[i].split(",", 2); columnSchemas[i] = new KuduTable.ColumnSchema( column[1], column[0], i == 0 ); } schema = new KuduTable.Schema(); schema.setColumns(columnSchemas, true); } options.put("operation", KuduDbOperations.CREATE_TABLE); options.put("type", KuduDbOperations.CREATE_TABLE); }
Example #21
Source File: KuduSQLParseTreeListener.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
public void setColumnSchemaList(List<ColumnSchema> listOfColumnsForCurrentTable) { Preconditions.checkNotNull(listOfColumnsForCurrentTable,"Column schemas " + "cannot be null for kudu table"); for (ColumnSchema aColumnDef : listOfColumnsForCurrentTable) { columnSchemaLookups.put(aColumnDef.getName(),aColumnDef); aliases.put(aColumnDef.getName(),aColumnDef.getName()); // By default each column is its own alias in POJO. } }
Example #22
Source File: NativeKuduClientSession.java From presto-kudu with Apache License 2.0 | 5 votes |
private void setCompression(String name, ColumnSchema.ColumnSchemaBuilder builder, ColumnDesign design) { if (design.getCompression() != null) { try { ColumnSchema.CompressionAlgorithm algorithm = ColumnSchema.CompressionAlgorithm.valueOf(design.getCompression().toUpperCase()); builder.compressionAlgorithm(algorithm); } catch (IllegalArgumentException e) { throw new RuntimeException("Unknown compression algorithm " + design.getCompression() + " for column " + name); } } }
Example #23
Source File: SQLToKuduPredicatesTranslatorTest.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
@KuduClusterTestContext(kuduClusterBasedTest = false) @Test public void testForColumnNameExtractionInSQLExpression() throws Exception { SQLToKuduPredicatesTranslator translator = new SQLToKuduPredicatesTranslator( " select introwkey as intColumn, ' from' as flColumn, stringCol from unittests", new ArrayList<ColumnSchema>(columnDefs.values())); assertEquals(1, translator.getKuduSQLParseTreeListener().getListOfColumnsUsed().size()); assertEquals(9, translator.getKuduSQLParseTreeListener().getAliases().size()); assertEquals("intColumn", translator.getKuduSQLParseTreeListener().getAliases().get("introwkey")); }
Example #24
Source File: KuduPartitionScannerCallableTest.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
@KuduClusterTestContext(kuduClusterBasedTest = true) @Test public void testRowScansForAllDataInSinglePartition() throws Exception { partitonScanStrategy = KuduPartitionScanStrategy.MANY_TABLETS_PER_OPERATOR; initOperatorState(); AbstractKuduPartitionScanner<UnitTestTablePojo,InputOperatorControlTuple> currentScanner = unitTestStepwiseScanInputOperator.getScanner(); // truncate and add some data to the unit test table truncateTable(); addTestDataRows(10); // This is per partition and there are 12 partitions assertEquals((10 * KuduClientTestCommons.TOTAL_KUDU_TABLETS_FOR_UNITTEST_TABLE),countNumRowsInTable()); int intRowBoundary = Integer.MAX_VALUE / SPLIT_COUNT_FOR_INT_ROW_KEY; // 5 to allow ofr scan to fall in lower SQLToKuduPredicatesTranslator translator = new SQLToKuduPredicatesTranslator( "select * from unittests where introwkey < " + intRowBoundary, new ArrayList<ColumnSchema>(columnDefs.values())); List<KuduPartitionScanAssignmentMeta> scansForThisQuery = currentScanner.preparePlanForScanners(translator); // Now scan for exact match of counts long totalRowsRead = 0; unitTestStepwiseScanInputOperator.getBuffer().clear(); for (KuduPartitionScanAssignmentMeta aSegmentToScan : scansForThisQuery) { KuduPartitionScannerCallable<UnitTestTablePojo,InputOperatorControlTuple> threadToScan = new KuduPartitionScannerCallable<>(unitTestStepwiseScanInputOperator,aSegmentToScan, currentScanner.getConnectionPoolForThreads().get(0), unitTestStepwiseScanInputOperator.extractSettersForResultObject(translator),translator); totalRowsRead += threadToScan.call(); } // 23 because of the hash distributions and the scan markers. 21 are data records and 2 are end of scan markers assertEquals(23L,unitTestStepwiseScanInputOperator.getBuffer().size()); // revert all configs to default partitonScanStrategy = KuduPartitionScanStrategy.ONE_TABLET_PER_OPERATOR; numberOfKuduInputOperatorPartitions = 5; }
Example #25
Source File: MetaTable.java From DataLink with Apache License 2.0 | 5 votes |
private void putColumnSchema(List<ColumnSchema> columnSchemas) { if (columnSchemas == null) { return; } for (ColumnSchema c : columnSchemas) { this.putColumnSchema(c); } }
Example #26
Source File: KuduColumnInfo.java From flink-learning with Apache License 2.0 | 5 votes |
protected ColumnSchema columnSchema() { return new ColumnSchema.ColumnSchemaBuilder(name, type) .key(key) .nullable(nullable) .defaultValue(defaultValue) .desiredBlockSize(blockSize) .encoding(encoding.encode) .compressionAlgorithm(compression.algorithm) .build(); }
Example #27
Source File: KuduProducerTest.java From syndesis with Apache License 2.0 | 5 votes |
@Ignore public void createTable() throws InterruptedException, KuduException { deleteTestTable(TABLE, HOST + ":" + PORT); errorEndpoint.expectedMessageCount(0); successEndpoint.expectedMessageCount(1); final Map<String, Object> headers = new HashMap<>(); final List<ColumnSchema> columns = new ArrayList<>(5); final List<String> columnNames = Arrays.asList("id", "title", "name", "lastname", "address"); for (int i = 0; i < columnNames.size(); i++) { columns.add( new ColumnSchema.ColumnSchemaBuilder(columnNames.get(i), Type.STRING) .key(i == 0) .build()); } final List<String> rangeKeys = new ArrayList<>(); rangeKeys.add("id"); headers.put("Schema", new Schema(columns)); headers.put("TableOptions", new CreateTableOptions().setRangePartitionColumns(rangeKeys)); requestBodyAndHeaders("direct://create", null, headers); errorEndpoint.assertIsSatisfied(); successEndpoint.assertIsSatisfied(); }
Example #28
Source File: NativeKuduClientSession.java From presto-kudu with Apache License 2.0 | 5 votes |
@Override public List<String> listSchemaNames() { try { if (rawSchemasTable == null) { if (!client.tableExists(rawSchemasTableName)) { createAndFillSchemasTable(); } rawSchemasTable = getSchemasTable(); } ColumnSchema tenantColumn = rawSchemasTable.getSchema().getColumnByIndex(0); KuduScanner scanner = client.newScannerBuilder(rawSchemasTable) .addPredicate(KuduPredicate.newComparisonPredicate(tenantColumn, KuduPredicate.ComparisonOp.EQUAL, tenantPrefix)) .setProjectedColumnIndexes(ImmutableList.of(1)) .build(); RowResultIterator iterator = scanner.nextRows(); ArrayList<String> result = new ArrayList<>(); while (iterator != null) { for (RowResult row : iterator) { result.add(row.getString(0)); } iterator = scanner.nextRows(); } return result; } catch (KuduException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, e); } }
Example #29
Source File: NativeKuduClientSession.java From presto-kudu with Apache License 2.0 | 5 votes |
private ColumnSchema toColumnSchema(ColumnMetadata columnMetadata, Map<String, ColumnDesign> columnDesignMap) { String name = columnMetadata.getName(); ColumnDesign design = columnDesignMap.getOrDefault(name, ColumnDesign.DEFAULT); Type ktype = TypeHelper.toKuduClientType(columnMetadata.getType()); ColumnSchema.ColumnSchemaBuilder builder = new ColumnSchema.ColumnSchemaBuilder(name, ktype); builder.key(design.isKey()).nullable(design.isNullable()); setEncoding(name, builder, design); setCompression(name, builder, design); setTypeAttributes(columnMetadata, builder); return builder.build(); }
Example #30
Source File: KuduRowUtils.java From DataLink with Apache License 2.0 | 5 votes |
public static void RecordWrite(Record record, PartialRow partialRow, MetaTable metaTable, List<String> configColumnNames) throws Exception { int columnNumber = record.getColumnNumber(); for (int i = 0; i < columnNumber; i++) { ColumnSchema columnSchema = metaTable.getColumnSchema(configColumnNames.get(i)); Object value = record.getColumn(i).getRawData(); if(value != null && !String.valueOf(value.toString()).trim().equals("") && record.getColumn(i).getType().equals(Column.Type.DATE)){ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); value = simpleDateFormat.format(record.getColumn(i).asDate()); } setValue(partialRow,value ,columnSchema); } }