@Test public void testPoly_contains() throws Exception { double[] poly = new double[]{ 45, 9.5, 45.5, 9.5, 45.5, 9, 46, 9, 46, 10, 45, 10 }; Block blockPoly = toBlock(poly); assertFalse(PolyContains.contains(DoubleType.DOUBLE, blockPoly, 6, 3)); assertFalse(PolyContains.contains(DoubleType.DOUBLE, blockPoly, 45, 9)); assertTrue(PolyContains.contains(DoubleType.DOUBLE, blockPoly, 45.7, 9.7)); }
public static JDBCType jdbcType(Type type) { if (type.equals(BooleanType.BOOLEAN)) { return JDBCType.BOOLEAN; } if (type.equals(BigintType.BIGINT) || type.equals(TimestampType.TIMESTAMP)) { return JDBCType.BIGINT; } if (type.equals(DoubleType.DOUBLE)) { return JDBCType.DOUBLE; } if (type.equals(DateType.DATE)) { return JDBCType.INTEGER; } if (type.equals(VarcharType.VARCHAR)) { return JDBCType.VARBINARY; } return null; }
private static ColumnStats doComputeColumnStats(OrcReader orcReader, long columnId, Type type) throws IOException { int columnIndex = columnIndex(orcReader.getColumnNames(), columnId); OrcRecordReader reader = orcReader.createRecordReader(ImmutableMap.of(columnIndex, type), OrcPredicate.TRUE, UTC, new AggregatedMemoryContext()); if (type.equals(BooleanType.BOOLEAN)) { return indexBoolean(type, reader, columnIndex, columnId); } if (type.equals(BigintType.BIGINT) || type.equals(DateType.DATE) || type.equals(TimestampType.TIMESTAMP)) { return indexLong(type, reader, columnIndex, columnId); } if (type.equals(DoubleType.DOUBLE)) { return indexDouble(type, reader, columnIndex, columnId); } if (type.equals(VarcharType.VARCHAR)) { return indexString(type, reader, columnIndex, columnId); } return null; }
@OutputFunction("map<double,double>") public static void output(State state, BlockBuilder out) { if (state.get() == null) { out.appendNull(); } else { Map<Double, Double> value = state.get().getBuckets(); BlockBuilder blockBuilder = DoubleType.DOUBLE.createBlockBuilder(new BlockBuilderStatus(), value.size() * 2); for (Map.Entry<Double, Double> entry : value.entrySet()) { DoubleType.DOUBLE.writeDouble(blockBuilder, entry.getKey()); DoubleType.DOUBLE.writeDouble(blockBuilder, entry.getValue()); } Block block = blockBuilder.build(); out.writeObject(block); out.closeEntry(); } }
@NotNull public static String serializeSessionProperty(Type type, Object value) { if (value == null) { throw new PrestoException(INVALID_SESSION_PROPERTY, "Session property can not be null"); } if (BooleanType.BOOLEAN.equals(type)) { return value.toString(); } if (BigintType.BIGINT.equals(type)) { return value.toString(); } if (DoubleType.DOUBLE.equals(type)) { return value.toString(); } if (VarcharType.VARCHAR.equals(type)) { return value.toString(); } if (type instanceof ArrayType || type instanceof MapType) { return getJsonCodecForType(type).toJson(value); } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type)); }
@NotNull private static Object deserializeSessionProperty(Type type, String value) { if (value == null) { throw new PrestoException(INVALID_SESSION_PROPERTY, "Session property can not be null"); } if (VarcharType.VARCHAR.equals(type)) { return value; } if (BooleanType.BOOLEAN.equals(type)) { return Boolean.valueOf(value); } if (BigintType.BIGINT.equals(type)) { return Long.valueOf(value); } if (DoubleType.DOUBLE.equals(type)) { return Double.valueOf(value); } if (type instanceof ArrayType || type instanceof MapType) { return getJsonCodecForType(type).fromJson(value); } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type)); }
private static <T> JsonCodec<T> getJsonCodecForType(Type type) { if (VarcharType.VARCHAR.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(String.class); } if (BooleanType.BOOLEAN.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Boolean.class); } if (BigintType.BIGINT.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Long.class); } if (DoubleType.DOUBLE.equals(type)) { return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Double.class); } if (type instanceof ArrayType) { Type elementType = ((ArrayType) type).getElementType(); return (JsonCodec<T>) JSON_CODEC_FACTORY.listJsonCodec(getJsonCodecForType(elementType)); } if (type instanceof MapType) { Type keyType = ((MapType) type).getKeyType(); Type valueType = ((MapType) type).getValueType(); return (JsonCodec<T>) JSON_CODEC_FACTORY.mapJsonCodec(getMapKeyType(keyType), getJsonCodecForType(valueType)); } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type)); }
private static Class<?> getMapKeyType(Type type) { if (VarcharType.VARCHAR.equals(type)) { return String.class; } if (BooleanType.BOOLEAN.equals(type)) { return Boolean.class; } if (BigintType.BIGINT.equals(type)) { return Long.class; } if (DoubleType.DOUBLE.equals(type)) { return Double.class; } throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property map key type %s is not supported", type)); }
@Test public void testNonExistent() throws Exception { byte[] json = "{}".getBytes(StandardCharsets.UTF_8); JsonRowDecoder rowDecoder = new JsonRowDecoder(PROVIDER.get()); DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", VarcharType.VARCHAR, "very/deep/varchar", null, null, false, false, false); DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", BigintType.BIGINT, "no_bigint", null, null, false, false, false); DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", DoubleType.DOUBLE, "double/is_missing", null, null, false, false, false); DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BooleanType.BOOLEAN, "hello", null, null, false, false, false); List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4); Set<FieldValueProvider> providers = new HashSet<>(); boolean corrupt = rowDecoder.decodeRow(json, null, providers, columns, buildMap(columns)); assertFalse(corrupt); assertEquals(providers.size(), columns.size()); checkIsNull(providers, row1); checkIsNull(providers, row2); checkIsNull(providers, row3); checkIsNull(providers, row4); }
@Test public void testNulls() { String csv = ",,,"; CsvRowDecoder rowDecoder = new CsvRowDecoder(); DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", VarcharType.VARCHAR, "0", null, null, false, false, false); DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", BigintType.BIGINT, "1", null, null, false, false, false); DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", DoubleType.DOUBLE, "2", null, null, false, false, false); DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BooleanType.BOOLEAN, "3", null, null, false, false, false); List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4); Set<FieldValueProvider> providers = new HashSet<>(); boolean corrupt = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null, providers, columns, buildMap(columns)); assertFalse(corrupt); assertEquals(providers.size(), columns.size()); checkValue(providers, row1, ""); checkValue(providers, row2, 0); checkValue(providers, row3, 0.0d); checkValue(providers, row4, false); }
@Test public void testNonExistent() throws Exception { byte[] json = "{}".getBytes(StandardCharsets.UTF_8); JsonKinesisRowDecoder rowDecoder = new JsonKinesisRowDecoder(PROVIDER.get()); KinesisColumnHandle row1 = new KinesisColumnHandle("", 0, "row1", VarcharType.VARCHAR, "very/deep/varchar", null, null, false, false); KinesisColumnHandle row2 = new KinesisColumnHandle("", 1, "row2", BigintType.BIGINT, "no_bigint", null, null, false, false); KinesisColumnHandle row3 = new KinesisColumnHandle("", 2, "row3", DoubleType.DOUBLE, "double/is_missing", null, null, false, false); KinesisColumnHandle row4 = new KinesisColumnHandle("", 3, "row4", BooleanType.BOOLEAN, "hello", null, null, false, false); List<KinesisColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4); Set<KinesisFieldValueProvider> providers = new HashSet<>(); boolean valid = rowDecoder.decodeRow(json, providers, columns, buildMap(columns)); assertTrue(valid); assertEquals(providers.size(), columns.size()); DecoderTestUtil.checkIsNull(providers, row1); DecoderTestUtil.checkIsNull(providers, row2); DecoderTestUtil.checkIsNull(providers, row3); DecoderTestUtil.checkIsNull(providers, row4); }
private List<String> toConjuncts(List<JdbcColumnHandle> columns, TupleDomain<ColumnHandle> tupleDomain) { ImmutableList.Builder<String> builder = ImmutableList.builder(); for (JdbcColumnHandle column : columns) { Type type = column.getColumnType(); if (type.equals(BigintType.BIGINT) || type.equals(DoubleType.DOUBLE) || type.equals(BooleanType.BOOLEAN)) { Domain domain = tupleDomain.getDomains().get().get(column); if (domain != null) { builder.add(toPredicate(column.getColumnName(), domain)); } } } return builder.build(); }
@Test public void testDouble() throws Exception { InternalAggregationFunction doubleAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("checksum", AGGREGATE, VARBINARY, DOUBLE)); Block block = createDoublesBlock(null, 2.0, null, 3.0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NaN); assertAggregation(doubleAgg, 1.0, expectedChecksum(DoubleType.DOUBLE, block), block); }
private static Block featuresHelper(double... features) { BlockBuilder blockBuilder = new VariableWidthBlockBuilder(new BlockBuilderStatus(), features.length, 8 + 8); for (int i = 0; i < features.length; i++) { BigintType.BIGINT.writeLong(blockBuilder, i); DoubleType.DOUBLE.writeDouble(blockBuilder, features[i]); } return blockBuilder.build(); }
private static Page getPage() throws JsonProcessingException { Type mapType = typeManager.getParameterizedType("map", ImmutableList.of(parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.DOUBLE)), ImmutableList.of()); int datapoints = 100; RowPageBuilder builder = RowPageBuilder.rowPageBuilder(BigintType.BIGINT, mapType, VarcharType.VARCHAR); Random rand = new Random(0); for (int i = 0; i < datapoints; i++) { long label = rand.nextDouble() < 0.5 ? 0 : 1; builder.row(label, mapSliceOf(BigintType.BIGINT, DoubleType.DOUBLE, 0, label + rand.nextGaussian()), "C=1"); } return builder.build(); }
public static ObjectInspector getRowColumnInspector(Type type) { if (type.equals(BooleanType.BOOLEAN)) { return writableBooleanObjectInspector; } if (type.equals(BigintType.BIGINT)) { return writableLongObjectInspector; } if (type.equals(DoubleType.DOUBLE)) { return writableDoubleObjectInspector; } if (type.equals(VarcharType.VARCHAR)) { return writableStringObjectInspector; } if (type.equals(VarbinaryType.VARBINARY)) { return writableBinaryObjectInspector; } if (type.equals(DateType.DATE)) { return writableDateObjectInspector; } if (type.equals(TimestampType.TIMESTAMP)) { return writableTimestampObjectInspector; } if (isArrayType(type) || isMapType(type) || isRowType(type)) { return getJavaObjectInspector(type); } throw new IllegalArgumentException("unsupported type: " + type); }
@Test public void testSimple() { String csv = "\"row 1\",row2,\"row3\",100,\"200\",300,4.5"; CsvRowDecoder rowDecoder = new CsvRowDecoder(); DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", VarcharType.VARCHAR, "0", null, null, false, false, false); DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", VarcharType.VARCHAR, "1", null, null, false, false, false); DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", VarcharType.VARCHAR, "2", null, null, false, false, false); DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BigintType.BIGINT, "3", null, null, false, false, false); DecoderTestColumnHandle row5 = new DecoderTestColumnHandle("", 4, "row5", BigintType.BIGINT, "4", null, null, false, false, false); DecoderTestColumnHandle row6 = new DecoderTestColumnHandle("", 5, "row6", BigintType.BIGINT, "5", null, null, false, false, false); DecoderTestColumnHandle row7 = new DecoderTestColumnHandle("", 6, "row7", DoubleType.DOUBLE, "6", null, null, false, false, false); List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4, row5, row6, row7); Set<FieldValueProvider> providers = new HashSet<>(); boolean corrupt = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null, providers, columns, buildMap(columns)); assertFalse(corrupt); assertEquals(providers.size(), columns.size()); checkValue(providers, row1, "row 1"); checkValue(providers, row2, "row2"); checkValue(providers, row3, "row3"); checkValue(providers, row4, 100); checkValue(providers, row5, 200); checkValue(providers, row6, 300); checkValue(providers, row7, 4.5d); }
private Type getType(TableType columnType) { switch (columnType) { case BOOLEAN: return BooleanType.BOOLEAN; case NUMBER: return DoubleType.DOUBLE; case STRING: return VarcharType.VARCHAR; default: throw new PrestoException(SpreadsheetErrorCode.INTERNAL_ERROR, "Not Supported [" + columnType + "]"); } }
@Test public void testSimple() { String csv = "\"row 1\",row2,\"row3\",100,\"200\",300,4.5"; CsvKinesisRowDecoder rowDecoder = new CsvKinesisRowDecoder(); KinesisColumnHandle row1 = new KinesisColumnHandle("", 0, "row1", VarcharType.VARCHAR, "0", null, null, false, false); KinesisColumnHandle row2 = new KinesisColumnHandle("", 1, "row2", VarcharType.VARCHAR, "1", null, null, false, false); KinesisColumnHandle row3 = new KinesisColumnHandle("", 2, "row3", VarcharType.VARCHAR, "2", null, null, false, false); KinesisColumnHandle row4 = new KinesisColumnHandle("", 3, "row4", BigintType.BIGINT, "3", null, null, false, false); KinesisColumnHandle row5 = new KinesisColumnHandle("", 4, "row5", BigintType.BIGINT, "4", null, null, false, false); KinesisColumnHandle row6 = new KinesisColumnHandle("", 5, "row6", BigintType.BIGINT, "5", null, null, false, false); KinesisColumnHandle row7 = new KinesisColumnHandle("", 6, "row7", DoubleType.DOUBLE, "6", null, null, false, false); List<KinesisColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4, row5, row6, row7); Set<KinesisFieldValueProvider> providers = new HashSet<>(); boolean valid = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), providers, columns, buildMap(columns)); assertTrue(valid); assertEquals(providers.size(), columns.size()); DecoderTestUtil.checkValue(providers, row1, "row 1"); DecoderTestUtil.checkValue(providers, row2, "row2"); DecoderTestUtil.checkValue(providers, row3, "row3"); DecoderTestUtil.checkValue(providers, row4, 100); DecoderTestUtil.checkValue(providers, row5, 200); DecoderTestUtil.checkValue(providers, row6, 300); DecoderTestUtil.checkValue(providers, row7, 4.5d); }
private Type getType(String typeName) { log.debug("Get type " + typeName); typeName = typeName.toLowerCase(); // check if type is varchar(xx) Pattern vcpattern = Pattern.compile("varchar\\(\\s*(\\d+)\\s*\\)"); Matcher vcmatcher = vcpattern.matcher(typeName); if (vcmatcher.find()) { String vlen = vcmatcher.group(1); if (!vlen.isEmpty()) { return VarcharType.createVarcharType(Integer.parseInt(vlen)); } return UnknownType.UNKNOWN; } // check if type is char(xx) Pattern cpattern = Pattern.compile("char\\(\\s*(\\d+)\\s*\\)"); Matcher cmatcher = cpattern.matcher(typeName); if (cmatcher.find()) { String clen = cmatcher.group(1); if (!clen.isEmpty()) { return CharType.createCharType(Integer.parseInt(clen)); } return UnknownType.UNKNOWN; } // check if type is decimal(precision, scale) Pattern dpattern = Pattern.compile("decimal\\((\\d+)\\s*,?\\s*(\\d*)\\)"); Matcher dmatcher = dpattern.matcher(typeName); if (dmatcher.find()) { String dprecision = dmatcher.group(1); String dscale = dmatcher.group(2); if (dprecision.isEmpty()) { return UnknownType.UNKNOWN; } if (dscale.isEmpty()) { return DecimalType.createDecimalType(Integer.parseInt(dprecision)); } return DecimalType.createDecimalType(Integer.parseInt(dprecision), Integer.parseInt(dscale)); } switch (typeName) { case "boolean": return BooleanType.BOOLEAN; case "tinyint": return TinyintType.TINYINT; case "smallint": return SmallintType.SMALLINT; case "integer": return IntegerType.INTEGER; case "bigint": return BigintType.BIGINT; case "real": return RealType.REAL; case "double": return DoubleType.DOUBLE; case "date": return DateType.DATE; case "time": return TimeType.TIME; case "timestamp": return TimestampType.TIMESTAMP; default: return UnknownType.UNKNOWN; } }
@SuppressWarnings("ValueOfIncrementOrDecrementUsed") @Override public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) { EthereumTableHandle ethereumTableHandle = convertTableHandle(tableHandle); String tableName = ethereumTableHandle.getTableName(); ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder(); int index = 0; if (EthereumTable.BLOCK.getName().equals(tableName)) { columnHandles.put("block_number", new EthereumColumnHandle(connectorId, index++, "block_number", BigintType.BIGINT)); columnHandles.put("block_hash", new EthereumColumnHandle(connectorId, index++, "block_hash", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); columnHandles.put("block_parentHash", new EthereumColumnHandle(connectorId, index++, "block_parentHash", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); columnHandles.put("block_nonce", new EthereumColumnHandle(connectorId, index++, "block_nonce", VarcharType.createVarcharType(H8_BYTE_HASH_STRING_LENGTH))); columnHandles.put("block_sha3Uncles", new EthereumColumnHandle(connectorId, index++, "block_sha3Uncles", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); columnHandles.put("block_logsBloom", new EthereumColumnHandle(connectorId, index++, "block_logsBloom", VarcharType.createVarcharType(H256_BYTE_HASH_STRING_LENGTH))); columnHandles.put("block_transactionsRoot", new EthereumColumnHandle(connectorId, index++, "block_transactionsRoot", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); columnHandles.put("block_stateRoot", new EthereumColumnHandle(connectorId, index++, "block_stateRoot", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); columnHandles.put("block_miner", new EthereumColumnHandle(connectorId, index++, "block_miner", VarcharType.createVarcharType(H20_BYTE_HASH_STRING_LENGTH))); columnHandles.put("block_difficulty", new EthereumColumnHandle(connectorId, index++, "block_difficulty", BigintType.BIGINT)); columnHandles.put("block_totalDifficulty", new EthereumColumnHandle(connectorId, index++, "block_totalDifficulty", BigintType.BIGINT)); columnHandles.put("block_size", new EthereumColumnHandle(connectorId, index++, "block_size", IntegerType.INTEGER)); columnHandles.put("block_extraData", new EthereumColumnHandle(connectorId, index++, "block_extraData", VarcharType.VARCHAR)); columnHandles.put("block_gasLimit", new EthereumColumnHandle(connectorId, index++, "block_gasLimit", DoubleType.DOUBLE)); columnHandles.put("block_gasUsed", new EthereumColumnHandle(connectorId, index++, "block_gasUsed", DoubleType.DOUBLE)); columnHandles.put("block_timestamp", new EthereumColumnHandle(connectorId, index++, "block_timestamp", BigintType.BIGINT)); columnHandles.put("block_transactions", new EthereumColumnHandle(connectorId, index++, "block_transactions", new ArrayType(VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH)))); columnHandles.put("block_uncles", new EthereumColumnHandle(connectorId, index++, "block_uncles", new ArrayType(VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH)))); } else if (EthereumTable.TRANSACTION.getName().equals(tableName)) { columnHandles.put("tx_hash", new EthereumColumnHandle(connectorId, index++, "tx_hash", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); columnHandles.put("tx_nonce", new EthereumColumnHandle(connectorId, index++, "tx_nonce", BigintType.BIGINT)); columnHandles.put("tx_blockHash", new EthereumColumnHandle(connectorId, index++, "tx_blockHash", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); columnHandles.put("tx_blockNumber", new EthereumColumnHandle(connectorId, index++, "tx_blockNumber", BigintType.BIGINT)); columnHandles.put("tx_transactionIndex", new EthereumColumnHandle(connectorId, index++, "tx_transactionIndex", IntegerType.INTEGER)); columnHandles.put("tx_from", new EthereumColumnHandle(connectorId, index++, "tx_from", VarcharType.createVarcharType(H20_BYTE_HASH_STRING_LENGTH))); columnHandles.put("tx_to", new EthereumColumnHandle(connectorId, index++, "tx_to", VarcharType.createVarcharType(H20_BYTE_HASH_STRING_LENGTH))); columnHandles.put("tx_value", new EthereumColumnHandle(connectorId, index++, "tx_value", DoubleType.DOUBLE)); columnHandles.put("tx_gas", new EthereumColumnHandle(connectorId, index++, "tx_gas", DoubleType.DOUBLE)); columnHandles.put("tx_gasPrice", new EthereumColumnHandle(connectorId, index++, "tx_gasPrice", DoubleType.DOUBLE)); columnHandles.put("tx_input", new EthereumColumnHandle(connectorId, index++, "tx_input", VarcharType.VARCHAR)); } else if (EthereumTable.ERC20.getName().equals(tableName)) { columnHandles.put("erc20_token", new EthereumColumnHandle(connectorId, index++, "erc20_token", VarcharType.createUnboundedVarcharType())); columnHandles.put("erc20_from", new EthereumColumnHandle(connectorId, index++, "erc20_from", VarcharType.createVarcharType(H20_BYTE_HASH_STRING_LENGTH))); columnHandles.put("erc20_to", new EthereumColumnHandle(connectorId, index++, "erc20_to", VarcharType.createVarcharType(H20_BYTE_HASH_STRING_LENGTH))); columnHandles.put("erc20_value", new EthereumColumnHandle(connectorId, index++, "erc20_value", DoubleType.DOUBLE)); columnHandles.put("erc20_txHash", new EthereumColumnHandle(connectorId, index++, "erc20_txHash", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); columnHandles.put("erc20_blockNumber", new EthereumColumnHandle(connectorId, index++, "erc20_blockNumber", BigintType.BIGINT)); } else { throw new IllegalArgumentException("Unknown Table Name " + tableName); } return columnHandles.build(); }
@SuppressWarnings("ValueOfIncrementOrDecrementUsed") private ConnectorTableMetadata getTableMetadata(SchemaTableName schemaTableName) { ImmutableList.Builder<ColumnMetadata> builder = ImmutableList.builder(); if (EthereumTable.BLOCK.getName().equals(schemaTableName.getTableName())) { builder.add(new ColumnMetadata("block_number", BigintType.BIGINT)); builder.add(new ColumnMetadata("block_hash", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("block_parentHash", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("block_nonce", VarcharType.createVarcharType(H8_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("block_sha3Uncles", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("block_logsBloom", VarcharType.createVarcharType(H256_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("block_transactionsRoot", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("block_stateRoot", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("block_miner", VarcharType.createVarcharType(H20_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("block_difficulty", BigintType.BIGINT)); builder.add(new ColumnMetadata("block_totalDifficulty", BigintType.BIGINT)); builder.add(new ColumnMetadata("block_size", IntegerType.INTEGER)); builder.add(new ColumnMetadata("block_extraData", VarcharType.VARCHAR)); builder.add(new ColumnMetadata("block_gasLimit", DoubleType.DOUBLE)); builder.add(new ColumnMetadata("block_gasUsed", DoubleType.DOUBLE)); builder.add(new ColumnMetadata("block_timestamp", BigintType.BIGINT)); builder.add(new ColumnMetadata("block_transactions", new ArrayType(VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH)))); builder.add(new ColumnMetadata("block_uncles", new ArrayType(VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH)))); } else if (EthereumTable.TRANSACTION.getName().equals(schemaTableName.getTableName())) { builder.add(new ColumnMetadata("tx_hash", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("tx_nonce", BigintType.BIGINT)); builder.add(new ColumnMetadata("tx_blockHash", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("tx_blockNumber", BigintType.BIGINT)); builder.add(new ColumnMetadata("tx_transactionIndex", IntegerType.INTEGER)); builder.add(new ColumnMetadata("tx_from", VarcharType.createVarcharType(H20_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("tx_to", VarcharType.createVarcharType(H20_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("tx_value", DoubleType.DOUBLE)); builder.add(new ColumnMetadata("tx_gas", DoubleType.DOUBLE)); builder.add(new ColumnMetadata("tx_gasPrice", DoubleType.DOUBLE)); builder.add(new ColumnMetadata("tx_input", VarcharType.VARCHAR)); } else if (EthereumTable.ERC20.getName().equals(schemaTableName.getTableName())) { builder.add(new ColumnMetadata("erc20_token", VarcharType.createUnboundedVarcharType())); builder.add(new ColumnMetadata("erc20_from", VarcharType.createVarcharType(H20_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("erc20_to", VarcharType.createVarcharType(H20_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("erc20_value", DoubleType.DOUBLE)); builder.add(new ColumnMetadata("erc20_txHash", VarcharType.createVarcharType(H32_BYTE_HASH_STRING_LENGTH))); builder.add(new ColumnMetadata("erc20_blockNumber", BigintType.BIGINT)); } else { throw new IllegalArgumentException("Unknown Table Name " + schemaTableName.getTableName()); } return new ConnectorTableMetadata(schemaTableName, builder.build()); }
@OutputFunction(StandardTypes.DOUBLE) public static void output(NullableDoubleState state, BlockBuilder out) { NullableDoubleState.write(DoubleType.DOUBLE, state, out); }
public static ObjectInspector getJavaObjectInspector(Type type) { if (type.equals(BooleanType.BOOLEAN)) { return javaBooleanObjectInspector; } else if (type.equals(BigintType.BIGINT)) { return javaLongObjectInspector; } else if (type.equals(DoubleType.DOUBLE)) { return javaDoubleObjectInspector; } else if (type.equals(VarcharType.VARCHAR)) { return writableStringObjectInspector; } else if (type.equals(VarbinaryType.VARBINARY)) { return javaByteArrayObjectInspector; } else if (type.equals(DateType.DATE)) { return javaDateObjectInspector; } else if (type.equals(TimestampType.TIMESTAMP)) { return javaTimestampObjectInspector; } else if (isArrayType(type)) { return ObjectInspectorFactory.getStandardListObjectInspector(getJavaObjectInspector(type.getTypeParameters().get(0))); } else if (isMapType(type)) { ObjectInspector keyObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(0)); ObjectInspector valueObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(1)); return ObjectInspectorFactory.getStandardMapObjectInspector(keyObjectInspector, valueObjectInspector); } else if (isRowType(type)) { return ObjectInspectorFactory.getStandardStructObjectInspector( type.getTypeSignature().getParameters().stream() .map(parameter -> parameter.getNamedTypeSignature().getName()) .collect(toList()), type.getTypeParameters().stream() .map(HiveWriteUtils::getJavaObjectInspector) .collect(toList())); } throw new IllegalArgumentException("unsupported type: " + type); }
public static FieldSetter createFieldSetter(SettableStructObjectInspector rowInspector, Object row, StructField field, Type type) { if (type.equals(BooleanType.BOOLEAN)) { return new BooleanFieldSetter(rowInspector, row, field); } if (type.equals(BigintType.BIGINT)) { return new BigintFieldBuilder(rowInspector, row, field); } if (type.equals(DoubleType.DOUBLE)) { return new DoubleFieldSetter(rowInspector, row, field); } if (type.equals(VarcharType.VARCHAR)) { return new VarcharFieldSetter(rowInspector, row, field); } if (type.equals(VarbinaryType.VARBINARY)) { return new BinaryFieldSetter(rowInspector, row, field); } if (type.equals(DateType.DATE)) { return new DateFieldSetter(rowInspector, row, field); } if (type.equals(TimestampType.TIMESTAMP)) { return new TimestampFieldSetter(rowInspector, row, field); } if (isArrayType(type)) { return new ArrayFieldSetter(rowInspector, row, field, type.getTypeParameters().get(0)); } if (isMapType(type)) { return new MapFieldSetter(rowInspector, row, field, type.getTypeParameters().get(0), type.getTypeParameters().get(1)); } if (isRowType(type)) { return new RowFieldSetter(rowInspector, row, field, type.getTypeParameters()); } throw new IllegalArgumentException("unsupported type: " + type); }
@Override public void setField(Block block, int position) { value.set(DoubleType.DOUBLE.getDouble(block, position)); rowInspector.setStructFieldData(row, field, value); }
private static void serializePrimitive(BlockBuilder builder, Object object, PrimitiveObjectInspector inspector) { requireNonNull(builder, "parent builder is null"); if (object == null) { builder.appendNull(); return; } switch (inspector.getPrimitiveCategory()) { case BOOLEAN: BooleanType.BOOLEAN.writeBoolean(builder, ((BooleanObjectInspector) inspector).get(object)); return; case BYTE: BigintType.BIGINT.writeLong(builder, ((ByteObjectInspector) inspector).get(object)); return; case SHORT: BigintType.BIGINT.writeLong(builder, ((ShortObjectInspector) inspector).get(object)); return; case INT: BigintType.BIGINT.writeLong(builder, ((IntObjectInspector) inspector).get(object)); return; case LONG: BigintType.BIGINT.writeLong(builder, ((LongObjectInspector) inspector).get(object)); return; case FLOAT: DoubleType.DOUBLE.writeDouble(builder, ((FloatObjectInspector) inspector).get(object)); return; case DOUBLE: DoubleType.DOUBLE.writeDouble(builder, ((DoubleObjectInspector) inspector).get(object)); return; case STRING: VarcharType.VARCHAR.writeSlice(builder, Slices.utf8Slice(((StringObjectInspector) inspector).getPrimitiveJavaObject(object))); return; case DATE: DateType.DATE.writeLong(builder, formatDateAsLong(object, (DateObjectInspector) inspector)); return; case TIMESTAMP: TimestampType.TIMESTAMP.writeLong(builder, formatTimestampAsLong(object, (TimestampObjectInspector) inspector)); return; case BINARY: VARBINARY.writeSlice(builder, Slices.wrappedBuffer(((BinaryObjectInspector) inspector).getPrimitiveJavaObject(object))); return; } throw new RuntimeException("Unknown primitive type: " + inspector.getPrimitiveCategory()); }
@Override public double getDouble(int field) { checkFieldType(field, DoubleType.DOUBLE); return Double.parseDouble(getFieldValue(field)); }