Java Code Examples for com.facebook.presto.spi.block.BlockBuilder#beginBlockEntry()
The following examples show how to use
com.facebook.presto.spi.block.BlockBuilder#beginBlockEntry() .
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: HbaseRowSerializerUtil.java From presto-connectors with Apache License 2.0 | 6 votes |
/** * Encodes the given map into a Block. * * @param mapType Presto type of the map * @param bytes hbase byte[] * @return Presto Block */ public static Block getBlockFromMap(Type mapType, byte[] bytes) throws IOException { Type keyType = mapType.getTypeParameters().get(0); Type valueType = mapType.getTypeParameters().get(1); Map<?, ?> map = MAPPER.readValue(bytes, new MyTypeReference(keyType.getJavaType(), valueType.getJavaType())); BlockBuilder mapBlockBuilder = mapType.createBlockBuilder(null, 1); BlockBuilder builder = mapBlockBuilder.beginBlockEntry(); for (Map.Entry<?, ?> entry : map.entrySet()) { writeObject(builder, keyType, entry.getKey()); writeObject(builder, valueType, entry.getValue()); } mapBlockBuilder.closeEntry(); return (Block) mapType.getObject(mapBlockBuilder, 0); }
Example 2
Source File: HbaseRowSerializerUtil.java From presto-connectors with Apache License 2.0 | 6 votes |
/** * Recursive helper function used by {@link this#getArrayFromBlock} and * {@link this#getMapFromBlock} to add the given object to the given block * builder. Supports nested complex types! * * @param builder Block builder * @param type Presto type * @param obj Object to write to the block builder */ private static void writeObject(BlockBuilder builder, Type type, Object obj) { if (Types.isArrayType(type)) { BlockBuilder arrayBldr = builder.beginBlockEntry(); Type elementType = Types.getElementType(type); for (Object item : (List<?>) obj) { writeObject(arrayBldr, elementType, item); } builder.closeEntry(); } else if (Types.isMapType(type)) { BlockBuilder mapBlockBuilder = builder.beginBlockEntry(); for (Map.Entry<?, ?> entry : ((Map<?, ?>) obj).entrySet()) { writeObject(mapBlockBuilder, Types.getKeyType(type), entry.getKey()); writeObject(mapBlockBuilder, Types.getValueType(type), entry.getValue()); } builder.closeEntry(); } else { TypeUtils.writeNativeValue(type, builder, obj); } }
Example 3
Source File: EthereumRecordCursor.java From presto-ethereum with Apache License 2.0 | 5 votes |
private static Block serializeList(Type type, BlockBuilder builder, Object object) { List<?> list = (List) object; if (list == null) { requireNonNull(builder, "parent builder is null").appendNull(); return null; } List<Type> typeParameters = type.getTypeParameters(); checkArgument(typeParameters.size() == 1, "list must have exactly 1 type parameter"); Type elementType = typeParameters.get(0); BlockBuilder currentBuilder; if (builder != null) { currentBuilder = builder.beginBlockEntry(); } else { currentBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), list.size()); } for (Object element : list) { serializeObject(elementType, currentBuilder, element); } if (builder != null) { builder.closeEntry(); return null; } else { Block resultBlock = currentBuilder.build(); return resultBlock; } }
Example 4
Source File: EthereumRecordCursor.java From presto-ethereum with Apache License 2.0 | 5 votes |
private static Block serializeMap(Type type, BlockBuilder builder, Object object) { Map<?, ?> map = (Map) object; if (map == null) { requireNonNull(builder, "parent builder is null").appendNull(); return null; } List<Type> typeParameters = type.getTypeParameters(); checkArgument(typeParameters.size() == 2, "map must have exactly 2 type parameter"); Type keyType = typeParameters.get(0); Type valueType = typeParameters.get(1); boolean builderSynthesized = false; if (builder == null) { builderSynthesized = true; builder = type.createBlockBuilder(new BlockBuilderStatus(), 1); } BlockBuilder currentBuilder = builder.beginBlockEntry(); for (Map.Entry<?, ?> entry : map.entrySet()) { // Hive skips map entries with null keys if (entry.getKey() != null) { serializeObject(keyType, currentBuilder, entry.getKey()); serializeObject(valueType, currentBuilder, entry.getValue()); } } builder.closeEntry(); if (builderSynthesized) { return (Block) type.getObject(builder, 0); } else { return null; } }
Example 5
Source File: EthereumRecordCursor.java From presto-ethereum with Apache License 2.0 | 5 votes |
private static Block serializeStruct(Type type, BlockBuilder builder, Object object) { if (object == null) { requireNonNull(builder, "parent builder is null").appendNull(); return null; } List<Type> typeParameters = type.getTypeParameters(); EthBlock.TransactionObject structData = (EthBlock.TransactionObject) object; boolean builderSynthesized = false; if (builder == null) { builderSynthesized = true; builder = type.createBlockBuilder(new BlockBuilderStatus(), 1); } BlockBuilder currentBuilder = builder.beginBlockEntry(); ImmutableList.Builder<Supplier> lstBuilder = ImmutableList.builder(); lstBuilder.add(structData::getHash); lstBuilder.add(structData::getNonce); lstBuilder.add(structData::getBlockHash); lstBuilder.add(structData::getBlockNumber); lstBuilder.add(structData::getTransactionIndex); lstBuilder.add(structData::getFrom); lstBuilder.add(structData::getTo); lstBuilder.add(structData::getValue); lstBuilder.add(structData::getGas); lstBuilder.add(structData::getGasPrice); lstBuilder.add(structData::getInput); ImmutableList<Supplier> txColumns = lstBuilder.build(); for (int i = 0; i < typeParameters.size(); i++) { serializeObject(typeParameters.get(i), currentBuilder, txColumns.get(i).get()); } builder.closeEntry(); if (builderSynthesized) { return (Block) type.getObject(builder, 0); } else { return null; } }