Skip to content

Commit

Permalink
Fix type mappings for decimal and inet
Browse files Browse the repository at this point in the history
  • Loading branch information
alexoss68 authored and dain committed Jun 26, 2014
1 parent e6ee836 commit ae71952
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.facebook.presto.spi.type.Type;
import com.facebook.presto.spi.type.VarcharType;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.net.InetAddresses;

import java.math.BigDecimal;
import java.math.BigInteger;
Expand All @@ -35,6 +36,7 @@

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.net.InetAddresses.toAddrString;

public enum CassandraType
implements FullCassandraType
Expand Down Expand Up @@ -194,7 +196,7 @@ public static Comparable<?> getColumnValue(Row row, int i, CassandraType cassand
case TIMESTAMP:
return row.getDate(i).getTime();
case INET:
return row.getInet(i).toString();
return toAddrString(row.getInet(i));
case VARINT:
return row.getVarint(i).toString();
case BLOB:
Expand Down Expand Up @@ -296,7 +298,7 @@ public static String getColumnValueForCql(Row row, int i, CassandraType cassandr
case TIMESTAMP:
return Long.toString(row.getDate(i).getTime());
case INET:
return row.getInet(i).toString();
return CassandraCqlUtils.quoteStringLiteral(toAddrString(row.getInet(i)));
case VARINT:
return row.getVarint(i).toString();
case BLOB:
Expand Down Expand Up @@ -372,17 +374,20 @@ public Object getJavaValue(Comparable<?> comparable)
case BIGINT:
case BOOLEAN:
case DOUBLE:
case INET:
case COUNTER:
return comparable;
case INET:
return InetAddresses.forString((String) comparable);
case INT:
return ((Long) comparable).intValue();
case FLOAT:
// conversion can result in precision lost
return ((Double) comparable).floatValue();
case DECIMAL:
// conversion can result in precision lost
return new BigDecimal((Double) comparable);
// Presto uses double for decimal, so to keep the floating point precision, convert it to string.
// Otherwise partition id doesn't match
return new BigDecimal(comparable.toString());
case TIMESTAMP:
return new Date((Long) comparable);
case UUID:
Expand Down

0 comments on commit ae71952

Please sign in to comment.