Skip to content

Commit

Permalink
Support Cassandra nested collection type
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Apr 24, 2019
1 parent feb818d commit 4ec5458
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 268 deletions.
Expand Up @@ -21,9 +21,6 @@
import io.prestosql.spi.connector.ColumnMetadata;
import io.prestosql.spi.type.Type;

import javax.annotation.Nullable;

import java.util.List;
import java.util.Objects;

import static com.google.common.base.MoreObjects.toStringHelper;
Expand All @@ -36,7 +33,6 @@ public class CassandraColumnHandle
private final String name;
private final int ordinalPosition;
private final CassandraType cassandraType;
private final List<CassandraType> typeArguments;
private final boolean partitionKey;
private final boolean clusteringKey;
private final boolean indexed;
Expand All @@ -47,7 +43,6 @@ public CassandraColumnHandle(
@JsonProperty("name") String name,
@JsonProperty("ordinalPosition") int ordinalPosition,
@JsonProperty("cassandraType") CassandraType cassandraType,
@Nullable @JsonProperty("typeArguments") List<CassandraType> typeArguments,
@JsonProperty("partitionKey") boolean partitionKey,
@JsonProperty("clusteringKey") boolean clusteringKey,
@JsonProperty("indexed") boolean indexed,
Expand All @@ -57,15 +52,6 @@ public CassandraColumnHandle(
checkArgument(ordinalPosition >= 0, "ordinalPosition is negative");
this.ordinalPosition = ordinalPosition;
this.cassandraType = requireNonNull(cassandraType, "cassandraType is null");
int typeArgsSize = cassandraType.getTypeArgumentSize();
if (typeArgsSize > 0) {
this.typeArguments = requireNonNull(typeArguments, "typeArguments is null");
checkArgument(typeArguments.size() == typeArgsSize, cassandraType
+ " must provide " + typeArgsSize + " type arguments");
}
else {
this.typeArguments = null;
}
this.partitionKey = partitionKey;
this.clusteringKey = clusteringKey;
this.indexed = indexed;
Expand All @@ -90,12 +76,6 @@ public CassandraType getCassandraType()
return cassandraType;
}

@JsonProperty
public List<CassandraType> getTypeArguments()
{
return typeArguments;
}

@JsonProperty
public boolean isPartitionKey()
{
Expand Down Expand Up @@ -130,22 +110,13 @@ public Type getType()
return cassandraType.getNativeType();
}

public FullCassandraType getFullType()
{
if (cassandraType.getTypeArgumentSize() == 0) {
return cassandraType;
}
return new CassandraTypeWithTypeArguments(cassandraType, typeArguments);
}

@Override
public int hashCode()
{
return Objects.hash(
name,
ordinalPosition,
cassandraType,
typeArguments,
partitionKey,
clusteringKey,
indexed,
Expand All @@ -165,7 +136,6 @@ public boolean equals(Object obj)
return Objects.equals(this.name, other.name) &&
Objects.equals(this.ordinalPosition, other.ordinalPosition) &&
Objects.equals(this.cassandraType, other.cassandraType) &&
Objects.equals(this.typeArguments, other.typeArguments) &&
Objects.equals(this.partitionKey, other.partitionKey) &&
Objects.equals(this.clusteringKey, other.clusteringKey) &&
Objects.equals(this.indexed, other.indexed) &&
Expand All @@ -180,10 +150,6 @@ public String toString()
.add("ordinalPosition", ordinalPosition)
.add("cassandraType", cassandraType);

if (typeArguments != null && !typeArguments.isEmpty()) {
helper.add("typeArguments", typeArguments);
}

helper.add("partitionKey", partitionKey)
.add("clusteringKey", clusteringKey)
.add("indexed", indexed)
Expand Down
Expand Up @@ -28,14 +28,14 @@
public class CassandraRecordCursor
implements RecordCursor
{
private final List<FullCassandraType> fullCassandraTypes;
private final List<CassandraType> cassandraTypes;
private final ResultSet rs;
private Row currentRow;
private long count;

public CassandraRecordCursor(CassandraSession cassandraSession, List<FullCassandraType> fullCassandraTypes, String cql)
public CassandraRecordCursor(CassandraSession cassandraSession, List<CassandraType> cassandraTypes, String cql)
{
this.fullCassandraTypes = fullCassandraTypes;
this.cassandraTypes = cassandraTypes;
rs = cassandraSession.execute(cql);
currentRow = null;
}
Expand Down Expand Up @@ -115,13 +115,13 @@ public long getLong(int i)

private CassandraType getCassandraType(int i)
{
return fullCassandraTypes.get(i).getCassandraType();
return cassandraTypes.get(i);
}

@Override
public Slice getSlice(int i)
{
NullableValue value = CassandraType.getColumnValue(currentRow, i, fullCassandraTypes.get(i));
NullableValue value = CassandraType.getColumnValue(currentRow, i, cassandraTypes.get(i));
if (value.getValue() instanceof Slice) {
return (Slice) value.getValue();
}
Expand Down
Expand Up @@ -29,7 +29,7 @@ public class CassandraRecordSet
{
private final CassandraSession cassandraSession;
private final String cql;
private final List<FullCassandraType> cassandraTypes;
private final List<CassandraType> cassandraTypes;
private final List<Type> columnTypes;

public CassandraRecordSet(CassandraSession cassandraSession, String cql, List<CassandraColumnHandle> cassandraColumns)
Expand All @@ -38,7 +38,7 @@ public CassandraRecordSet(CassandraSession cassandraSession, String cql, List<Ca
this.cql = requireNonNull(cql, "cql is null");

requireNonNull(cassandraColumns, "cassandraColumns is null");
this.cassandraTypes = transformList(cassandraColumns, CassandraColumnHandle::getFullType);
this.cassandraTypes = transformList(cassandraColumns, CassandraColumnHandle::getCassandraType);
this.columnTypes = transformList(cassandraColumns, CassandraColumnHandle::getType);
}

Expand Down

0 comments on commit 4ec5458

Please sign in to comment.