Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/trino-record-decoder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@
<artifactId>jackson-databind</artifactId>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
package io.trino.decoder;

import javax.annotation.Nullable;

import java.util.Map;
import java.util.Optional;

Expand All @@ -29,18 +27,5 @@ public interface RowDecoder
* @param data The row data to decode.
* @return Returns mapping from column handle to decoded value. Unmapped columns will be reported as null. Optional.empty() signals decoding error.
*/
default Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data)
{
return decodeRow(data, null);
}

/**
* Decodes a given sequence of bytes into field values.
*
* @param data The row data to decode.
* @param dataMap The row data as fields map
* @return Returns mapping from column handle to decoded value. Unmapped columns will be reported as null. Optional.empty() signals decoding error.
*/
// TODO This is Redis-specific, move to trino-redis
Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data, @Nullable Map<String, String> dataMap);
Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public GenericRecordRowDecoder(AvroDeserializer<GenericRecord> deserializer, Set
}

@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data, Map<String, String> dataMap)
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data)
{
GenericRecord avroRecord = deserializer.deserialize(data);
return Optional.of(columnDecoders.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public SingleValueRowDecoder(AvroDeserializer<Object> deserializer, DecoderColum
}

@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data, Map<String, String> dataMap)
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data)
{
Object avroValue = deserializer.deserialize(data);
return Optional.of(ImmutableMap.of(column, new AvroColumnDecoder.ObjectValueProvider(avroValue, column.getType(), column.getName())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private CsvColumnDecoder createColumnDecoder(DecoderColumnHandle columnHandle)
}

@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data, Map<String, String> dataMap)
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data)
{
String[] tokens;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public class DummyRowDecoder
private static final Optional<Map<DecoderColumnHandle, FieldValueProvider>> ALL_NULLS = Optional.of(ImmutableMap.of());

@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data,
Map<String, String> dataMap)
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data)
{
return ALL_NULLS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public class JsonRowDecoder
}

@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data,
Map<String, String> dataMap)
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data)
{
JsonNode tree;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private RawColumnDecoder createColumnDecoder(DecoderColumnHandle columnHandle)
}

@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data, Map<String, String> dataMap)
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data)
{
return Optional.of(columnDecoders.entrySet().stream()
.collect(toImmutableMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ public void testSingleValueRow()
private static void testRow(RowDecoder rowDecoder, GenericRecord record, int schemaId)
{
byte[] serializedRecord = serializeRecord(record, record.getSchema(), schemaId);
Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodedRow = rowDecoder.decodeRow(serializedRecord, null);
Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodedRow = rowDecoder.decodeRow(serializedRecord);
assertRowsAreEqual(decodedRow, record);
}

private static void testSingleValueRow(RowDecoder rowDecoder, Object value, Schema schema, int schemaId)
{
byte[] serializedRecord = serializeRecord(value, schema, schemaId);
Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodedRow = rowDecoder.decodeRow(serializedRecord, null);
Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodedRow = rowDecoder.decodeRow(serializedRecord);
checkState(decodedRow.isPresent(), "decodedRow is not present");
Map.Entry<DecoderColumnHandle, FieldValueProvider> entry = getOnlyElement(decodedRow.get().entrySet());
assertValuesAreEqual(entry.getValue(), value, schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.trino.decoder.DecoderColumnHandle;
import io.trino.decoder.FieldValueProvider;
import io.trino.decoder.RowDecoder;
import io.trino.plugin.redis.decoder.RedisRowDecoder;
import io.trino.spi.connector.ColumnHandle;
import io.trino.spi.connector.RecordCursor;
import io.trino.spi.type.Type;
Expand Down Expand Up @@ -200,10 +201,13 @@ private void generateRowValues(String keyString, String valueString, @Nullable M
{
byte[] keyData = keyString.getBytes(StandardCharsets.UTF_8);
byte[] stringValueData = valueString.getBytes(StandardCharsets.UTF_8);
// Redis connector supports two types of Redis values: STRING and HASH. HASH type requires hash row decoder to
// decode a row from map, whereas for the STRING type decoders are optional. The redis keyData is always byte array,
// so the decoder of key always decodes a row from bytes.
Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodedKey = keyDecoder.decodeRow(keyData);
Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodedValue = valueDecoder.decodeRow(
stringValueData,
hashValueMap);
Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodedValue = valueDecoder instanceof RedisRowDecoder
Comment thread
ebyhr marked this conversation as resolved.
? ((RedisRowDecoder) valueDecoder).decodeRow(hashValueMap)
: valueDecoder.decodeRow(stringValueData);

totalBytes += stringValueData.length;
totalValues++;
Expand Down Expand Up @@ -367,11 +371,6 @@ private void fetchData(List<String> currentKeys)
{
stringValues = null;
hashValues = null;
// Redis connector supports two types of Redis
// values: STRING and HASH
// HASH types requires hash row decoder to
// fill in the columns
// whereas for the STRING type decoders are optional
try (Jedis jedis = jedisPool.getResource()) {
switch (split.getValueDataType()) {
case STRING:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.plugin.redis.decoder;

import io.trino.decoder.DecoderColumnHandle;
import io.trino.decoder.FieldValueProvider;
import io.trino.decoder.RowDecoder;

import javax.annotation.Nullable;

import java.util.Map;
import java.util.Optional;

/**
* Implementations decode a row from map and add field value providers for all decodable columns.
*/
public interface RedisRowDecoder
extends RowDecoder
{
/**
* Decodes a given map into field values.
*
* @param dataMap The row data as fields map
* @return Returns mapping from column handle to decoded value. Unmapped columns will be reported as null. Optional.empty() signals decoding error.
*/
Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(@Nullable Map<String, String> dataMap);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import com.google.common.collect.ImmutableMap;
import io.trino.decoder.DecoderColumnHandle;
import io.trino.decoder.FieldValueProvider;
import io.trino.decoder.RowDecoder;
import io.trino.plugin.redis.RedisFieldDecoder;
import io.trino.plugin.redis.decoder.RedisRowDecoder;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -30,7 +30,7 @@
* The row decoder for the Redis values that are stored in Hash format.
*/
public class HashRedisRowDecoder
implements RowDecoder
implements RedisRowDecoder
{
public static final String NAME = "hash";

Expand All @@ -42,7 +42,7 @@ public HashRedisRowDecoder(Map<DecoderColumnHandle, RedisFieldDecoder<String>> f
}

@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data, Map<String, String> dataMap)
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(Map<String, String> dataMap)
{
if (dataMap == null) {
return Optional.of(emptyMap());
Expand All @@ -62,4 +62,10 @@ public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] d
}
return Optional.of(decodedRow);
}

@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data)
{
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
package io.trino.plugin.redis.decoder.hash;

import io.trino.decoder.DecoderColumnHandle;
import io.trino.decoder.RowDecoder;
import io.trino.decoder.RowDecoderFactory;
import io.trino.plugin.redis.RedisFieldDecoder;
import io.trino.plugin.redis.decoder.RedisRowDecoder;

import java.util.Map;
import java.util.Set;
Expand All @@ -31,7 +31,7 @@ public class HashRedisRowDecoderFactory
implements RowDecoderFactory
{
@Override
public RowDecoder create(Map<String, String> decoderParams, Set<DecoderColumnHandle> columns)
public RedisRowDecoder create(Map<String, String> decoderParams, Set<DecoderColumnHandle> columns)
{
requireNonNull(columns, "columns is null");
return new HashRedisRowDecoder(chooseFieldDecoders(columns));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import io.trino.decoder.DecoderColumnHandle;
import io.trino.decoder.FieldValueProvider;
import io.trino.decoder.RowDecoder;
import io.trino.plugin.redis.decoder.RedisRowDecoder;

import java.util.Map;
import java.util.Optional;
Expand All @@ -26,14 +26,18 @@
* The row decoder for the 'zset' format. Zset's can contain redis keys for tables
*/
public class ZsetRedisRowDecoder
implements RowDecoder
implements RedisRowDecoder
{
public static final String NAME = "zset";

@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(
byte[] data,
Map<String, String> dataMap)
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(Map<String, String> dataMap)
{
throw new UnsupportedOperationException();
}

@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data)
{
return Optional.of(emptyMap());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
package io.trino.plugin.redis.decoder.zset;

import io.trino.decoder.DecoderColumnHandle;
import io.trino.decoder.RowDecoder;
import io.trino.decoder.RowDecoderFactory;
import io.trino.plugin.redis.decoder.RedisRowDecoder;

import java.util.Map;
import java.util.Set;
Expand All @@ -26,10 +26,10 @@
public class ZsetRedisRowDecoderFactory
implements RowDecoderFactory
{
private static final RowDecoder DECODER_INSTANCE = new ZsetRedisRowDecoder();
private static final RedisRowDecoder DECODER_INSTANCE = new ZsetRedisRowDecoder();

@Override
public RowDecoder create(Map<String, String> decoderParams, Set<DecoderColumnHandle> columns)
public RedisRowDecoder create(Map<String, String> decoderParams, Set<DecoderColumnHandle> columns)
{
requireNonNull(columns, "columns is null");
checkArgument(columns.stream().noneMatch(DecoderColumnHandle::isInternal), "unexpected internal column");
Expand Down