Java Code Examples for org.apache.kudu.ColumnSchema#getName()
The following examples show how to use
org.apache.kudu.ColumnSchema#getName() .
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: KuduMetadata.java From presto with Apache License 2.0 | 6 votes |
@Override public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle connectorTableHandle) { KuduTableHandle tableHandle = (KuduTableHandle) connectorTableHandle; Schema schema = clientSession.getTableSchema(tableHandle); ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder(); for (int ordinal = 0; ordinal < schema.getColumnCount(); ordinal++) { ColumnSchema col = schema.getColumnByIndex(ordinal); String name = col.getName(); Type type = TypeHelper.fromKuduColumn(col); KuduColumnHandle columnHandle = new KuduColumnHandle(name, ordinal, type); columnHandles.put(name, columnHandle); } return columnHandles.build(); }
Example 2
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 3
Source File: KuduMetadata.java From presto-kudu with Apache License 2.0 | 6 votes |
@Override public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle connectorTableHandle) { KuduTableHandle tableHandle = fromConnectorTableHandle(session, connectorTableHandle); Schema schema = clientSession.getTableSchema(tableHandle); ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder(); for (int i = 0; i < schema.getColumnCount(); i++) { ColumnSchema col = schema.getColumnByIndex(i); String name = col.getName(); Type type = TypeHelper.fromKuduColumn(col); KuduColumnHandle columnHandle = new KuduColumnHandle(name, i, type); columnHandles.put(name, columnHandle); } return columnHandles.build(); }
Example 4
Source File: KuduClientSession.java From presto with Apache License 2.0 | 5 votes |
private KuduPredicate createComparisonPredicate(ColumnSchema columnSchema, KuduPredicate.ComparisonOp op, Object value) { io.prestosql.spi.type.Type type = TypeHelper.fromKuduColumn(columnSchema); Object javaValue = TypeHelper.getJavaValue(type, value); if (javaValue instanceof Long) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Long) javaValue); } if (javaValue instanceof BigDecimal) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (BigDecimal) javaValue); } if (javaValue instanceof Integer) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Integer) javaValue); } if (javaValue instanceof Short) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Short) javaValue); } if (javaValue instanceof Byte) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Byte) javaValue); } if (javaValue instanceof String) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (String) javaValue); } if (javaValue instanceof Double) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Double) javaValue); } if (javaValue instanceof Float) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Float) javaValue); } if (javaValue instanceof Boolean) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Boolean) javaValue); } if (javaValue instanceof byte[]) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (byte[]) javaValue); } if (javaValue == null) { throw new IllegalStateException("Unexpected null java value for column " + columnSchema.getName()); } throw new IllegalStateException("Unexpected java value for column " + columnSchema.getName() + ": " + javaValue + "(" + javaValue.getClass() + ")"); }
Example 5
Source File: NativeKuduClientSession.java From presto-kudu with Apache License 2.0 | 5 votes |
private KuduPredicate createComparisonPredicate(ColumnSchema columnSchema, KuduPredicate.ComparisonOp op, Object value) { com.facebook.presto.spi.type.Type type = TypeHelper.fromKuduColumn(columnSchema); Object javaValue = TypeHelper.getJavaValue(type, value); if (javaValue instanceof Long) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Long) javaValue); } else if (javaValue instanceof Integer) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Integer) javaValue); } else if (javaValue instanceof Short) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Short) javaValue); } else if (javaValue instanceof Byte) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Byte) javaValue); } else if (javaValue instanceof String) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (String) javaValue); } else if (javaValue instanceof Double) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Double) javaValue); } else if (javaValue instanceof Float) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Float) javaValue); } else if (javaValue instanceof Boolean) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (Boolean) javaValue); } else if (javaValue instanceof byte[]) { return KuduPredicate.newComparisonPredicate(columnSchema, op, (byte[]) javaValue); } else if (javaValue == null) { throw new IllegalStateException("Unexpected null java value for column " + columnSchema.getName()); } else { throw new IllegalStateException("Unexpected java value for column " + columnSchema.getName() + ": " + javaValue + "(" + javaValue.getClass() + ")"); } }
Example 6
Source File: KuduMetadataRetrieval.java From syndesis with Apache License 2.0 | 4 votes |
private static ObjectSchema createSpec(KuduMetaData kuduMetaData) { // build the input and output schemas ObjectSchema spec = new ObjectSchema(); spec.set$schema(JSON_SCHEMA_ORG_SCHEMA); spec.setTitle("KUDU_INSERT"); Map<String, Object> options = new HashMap<>(); options.put("host", kuduMetaData.getHost()); options.put("port", kuduMetaData.getPort()); KuduClient client = KuduSupport.createConnection(options); try { KuduTable table = client.openTable(kuduMetaData.getTableName()); Iterator<ColumnSchema> columns = table.getSchema().getColumns().iterator(); while (columns.hasNext()) { ColumnSchema column = columns.next(); switch (column.getType().getName()) { case "string": spec.putProperty(column.getName(), new JsonSchemaFactory().stringSchema()); break; case "bool": spec.putProperty(column.getName(), new JsonSchemaFactory().booleanSchema()); break; case "float": case "double": case "int8": case "int16": case "int32": case "int64": spec.putProperty(column.getName(), new JsonSchemaFactory().integerSchema()); break; default: throw new SyndesisServerException("The column schema type " + column.getType().getName() + " for column " + column.getName() + " is not supported at the moment"); } } } catch (KuduException e) { throw new SyndesisServerException("Unable to connect to kudu schema " + kuduMetaData.getTableName(), e); } return spec; }
Example 7
Source File: KuduOutput.java From envelope with Apache License 2.0 | 4 votes |
private Row resultAsRow(RowResult result, KuduTable table) throws KuduException { List<Object> values = Lists.newArrayList(); for (ColumnSchema columnSchema : table.getSchema().getColumns()) { String columnName = columnSchema.getName(); if (result.isNull(columnName)) { values.add(null); continue; } switch (columnSchema.getType()) { case DOUBLE: values.add(result.getDouble(columnName)); break; case FLOAT: values.add(result.getFloat(columnName)); break; case INT8: values.add(result.getByte(columnName)); break; case INT16: values.add(result.getShort(columnName)); break; case INT32: values.add(result.getInt(columnName)); break; case INT64: values.add(result.getLong(columnName)); break; case STRING: values.add(result.getString(columnName)); break; case BOOL: values.add(result.getBoolean(columnName)); break; case BINARY: values.add(result.getBinaryCopy(columnName)); break; case UNIXTIME_MICROS: values.add(result.getTimestamp(columnName)); break; case DECIMAL: values.add(result.getDecimal(columnName)); break; default: throw new RuntimeException("Unsupported Kudu column type: " + columnSchema.getType()); } } Row row = new RowWithSchema(getTableSchema(table), values.toArray()); return row; }
Example 8
Source File: AbstractKuduInputOperator.java From attic-apex-malhar with Apache License 2.0 | 4 votes |
/*** * * @param parsedQuery The parsed query string * @return Null if the SQL expression cannot be mapped properly to the POJO fields in which case the SQL string is * sent to the Error port */ public Map<String,Object> extractSettersForResultObject(SQLToKuduPredicatesTranslator parsedQuery) { Map<String,String> aliasesUsedForThisQuery = parsedQuery.getKuduSQLParseTreeListener().getAliases(); Map<String,Object> setterMap = new HashMap<>(); Field[] fieldsOfThisPojo = clazzForResultObject.getDeclaredFields(); Set<String> allPojoFieldNamesUsed = new HashSet<>(aliasesUsedForThisQuery.values()); for ( Field aField : fieldsOfThisPojo) { if (!allPojoFieldNamesUsed.contains(aField.getName())) { LOG.error("Invalid mapping fo Kudu table column name to the POJO field name " + aField.getName()); return null; // SQL expression will be sent to the error port } } for (ColumnSchema aKuduTableColumn: kuduColNameToSchemaMapping.values()) { String kuduColumnName = aKuduTableColumn.getName(); switch ( aKuduTableColumn.getType().getDataType().getNumber()) { case Common.DataType.BINARY_VALUE: setterMap.put(kuduColumnName,PojoUtils.createSetter(clazzForResultObject, aliasesUsedForThisQuery.get(kuduColumnName),ByteBuffer.class)); break; case Common.DataType.BOOL_VALUE: setterMap.put(kuduColumnName,PojoUtils.createSetterBoolean(clazzForResultObject, aliasesUsedForThisQuery.get(kuduColumnName))); break; case Common.DataType.DOUBLE_VALUE: setterMap.put(kuduColumnName,PojoUtils.createSetterDouble(clazzForResultObject, aliasesUsedForThisQuery.get(kuduColumnName))); break; case Common.DataType.FLOAT_VALUE: setterMap.put(kuduColumnName,PojoUtils.createSetterFloat(clazzForResultObject, aliasesUsedForThisQuery.get(kuduColumnName))); break; case Common.DataType.INT8_VALUE: setterMap.put(kuduColumnName,PojoUtils.createSetterByte(clazzForResultObject, aliasesUsedForThisQuery.get(kuduColumnName))); break; case Common.DataType.INT16_VALUE: setterMap.put(kuduColumnName,PojoUtils.createSetterShort(clazzForResultObject, aliasesUsedForThisQuery.get(kuduColumnName))); break; case Common.DataType.INT32_VALUE: setterMap.put(kuduColumnName,PojoUtils.createSetterInt(clazzForResultObject, aliasesUsedForThisQuery.get(kuduColumnName))); break; case Common.DataType.UNIXTIME_MICROS_VALUE: case Common.DataType.INT64_VALUE: setterMap.put(kuduColumnName,PojoUtils.createSetterLong(clazzForResultObject, aliasesUsedForThisQuery.get(kuduColumnName))); break; case Common.DataType.STRING_VALUE: setterMap.put(kuduColumnName,PojoUtils.createSetter(clazzForResultObject, aliasesUsedForThisQuery.get(kuduColumnName),String.class)); break; case Common.DataType.UINT8_VALUE: LOG.error("Unsigned int 8 not supported yet"); throw new RuntimeException("uint8 not supported in Kudu schema yet"); case Common.DataType.UINT16_VALUE: LOG.error("Unsigned int 16 not supported yet"); throw new RuntimeException("uint16 not supported in Kudu schema yet"); case Common.DataType.UINT32_VALUE: LOG.error("Unsigned int 32 not supported yet"); throw new RuntimeException("uint32 not supported in Kudu schema yet"); case Common.DataType.UINT64_VALUE: LOG.error("Unsigned int 64 not supported yet"); throw new RuntimeException("uint64 not supported in Kudu schema yet"); case Common.DataType.UNKNOWN_DATA_VALUE: LOG.error("unknown data type ( complex types ? ) not supported yet"); throw new RuntimeException("Unknown data type ( complex types ? ) not supported in Kudu schema yet"); default: LOG.error("unknown type/default ( complex types ? ) not supported yet"); throw new RuntimeException("Unknown type/default ( complex types ? ) not supported in Kudu schema yet"); } } return setterMap; }