Java Code Examples for org.apache.kudu.client.RowResult#getColumnType()
The following examples show how to use
org.apache.kudu.client.RowResult#getColumnType() .
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: KuduLookupService.java From nifi with Apache License 2.0 | 5 votes |
@Override public Optional<Record> lookup(Map<String, Object> coordinates) { //Scanner KuduScanner.KuduScannerBuilder builder = kuduClient.newScannerBuilder(table); builder.setProjectedColumnNames(columnNames); builder.replicaSelection(replicaSelection); //Only expecting one match builder.limit(1); coordinates.forEach((key,value)-> builder.addPredicate(KuduPredicate.newComparisonPredicate(tableSchema.getColumn(key), KuduPredicate.ComparisonOp.EQUAL, value)) ); KuduScanner kuduScanner = builder.build(); //Run lookup for ( RowResult row : kuduScanner){ final Map<String, Object> values = new HashMap<>(); for(String columnName : columnNames){ Object object; if(row.getColumnType(columnName) == Type.BINARY){ object = Base64.getEncoder().encodeToString(row.getBinaryCopy(columnName)); } else { object = row.getObject(columnName); } values.put(columnName, object); } return Optional.of(new MapRecord(resultSchema, values)); } //No match return Optional.empty(); }
Example 2
Source File: KuduScanCustomizer.java From syndesis with Apache License 2.0 | 4 votes |
private static void processBody(Exchange exchange) throws KuduException, JsonProcessingException { final Message in = exchange.getIn(); final KuduScanner scanner = in.getBody(KuduScanner.class); final List<String> answer = new ArrayList<>(); while(scanner.hasMoreRows()) { RowResultIterator results = scanner.nextRows(); while (results.hasNext()) { Map<String, Object> row = new HashMap<String, Object>(); RowResult result = results.next(); for (int i = 0; i < result.getSchema().getColumnCount(); i++) { String key = result.getSchema().getColumnByIndex(i).getName(); Type type = result.getColumnType(i); switch (type.getName()) { case "string": row.put(key, result.getString(i)); break; case "bool": row.put(key, result.getBoolean(i)); break; case "int8": case "int16": case "int32": row.put(key, result.getInt(i)); break; case "int64": row.put(key, result.getLong(i)); break; case "double": row.put(key, result.getDouble(i)); break; case "float": row.put(key, result.getFloat(i)); break; default: throw new SyndesisServerException("The column schema type " + type.getName() + " for column " + key + " is not supported at the moment"); } } answer.add(KuduSupport.toJSONBean(row)); } } in.setBody(answer); }