Search in sources :

Example 1 with ArrayBasedMapData

use of org.apache.spark.sql.catalyst.util.ArrayBasedMapData in project java-pubsublite-spark by googleapis.

the class PslSparkUtils method convertAttributesToSparkMap.

@VisibleForTesting
public static ArrayBasedMapData convertAttributesToSparkMap(ListMultimap<String, ByteString> attributeMap) {
    List<UTF8String> keyList = new ArrayList<>();
    List<GenericArrayData> valueList = new ArrayList<>();
    attributeMap.asMap().forEach((key, value) -> {
        keyList.add(UTF8String.fromString(key));
        List<byte[]> attributeVals = value.stream().map(v -> ByteArray.concat(v.toByteArray())).collect(Collectors.toList());
        valueList.add(new GenericArrayData(asScalaBufferConverter(attributeVals).asScala()));
    });
    return new ArrayBasedMapData(new GenericArrayData(asScalaBufferConverter(keyList).asScala()), new GenericArrayData(asScalaBufferConverter(valueList).asScala()));
}
Also used : DataType(org.apache.spark.sql.types.DataType) CursorClient(com.google.cloud.pubsublite.internal.CursorClient) Arrays(java.util.Arrays) InternalRow(org.apache.spark.sql.catalyst.InternalRow) ListMultimap(com.google.common.collect.ListMultimap) GenericArrayData(org.apache.spark.sql.catalyst.util.GenericArrayData) HashMap(java.util.HashMap) SequencedMessage(com.google.cloud.pubsublite.SequencedMessage) SubscriptionPath(com.google.cloud.pubsublite.SubscriptionPath) Message(com.google.cloud.pubsublite.Message) ArrayList(java.util.ArrayList) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Map(java.util.Map) UTF8String(org.apache.spark.unsafe.types.UTF8String) JavaConverters.asScalaBufferConverter(scala.collection.JavaConverters.asScalaBufferConverter) ArrayData(org.apache.spark.sql.catalyst.util.ArrayData) DataTypes(org.apache.spark.sql.types.DataTypes) StructField(org.apache.spark.sql.types.StructField) StructType(org.apache.spark.sql.types.StructType) Partition(com.google.cloud.pubsublite.Partition) Offset(com.google.cloud.pubsublite.Offset) Timestamps(com.google.protobuf.util.Timestamps) LongMath(com.google.common.math.LongMath) Option(scala.Option) GoogleLogger(com.google.common.flogger.GoogleLogger) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) MapData(org.apache.spark.sql.catalyst.util.MapData) ByteArray(org.apache.spark.unsafe.types.ByteArray) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) FromJavaBiConsumer(scala.compat.java8.functionConverterImpls.FromJavaBiConsumer) ArrayBasedMapData(org.apache.spark.sql.catalyst.util.ArrayBasedMapData) VisibleForTesting(com.google.common.annotations.VisibleForTesting) UTF8String(org.apache.spark.unsafe.types.UTF8String) GenericArrayData(org.apache.spark.sql.catalyst.util.GenericArrayData) ArrayBasedMapData(org.apache.spark.sql.catalyst.util.ArrayBasedMapData) ArrayList(java.util.ArrayList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Message (com.google.cloud.pubsublite.Message)1 Offset (com.google.cloud.pubsublite.Offset)1 Partition (com.google.cloud.pubsublite.Partition)1 SequencedMessage (com.google.cloud.pubsublite.SequencedMessage)1 SubscriptionPath (com.google.cloud.pubsublite.SubscriptionPath)1 CursorClient (com.google.cloud.pubsublite.internal.CursorClient)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ListMultimap (com.google.common.collect.ListMultimap)1 GoogleLogger (com.google.common.flogger.GoogleLogger)1 LongMath (com.google.common.math.LongMath)1 ByteString (com.google.protobuf.ByteString)1 Timestamps (com.google.protobuf.util.Timestamps)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1