diff --git a/src/main/java/org/polypheny/jdbc/ProtoInterfaceClient.java b/src/main/java/org/polypheny/jdbc/ProtoInterfaceClient.java index 91d79124..4b4aab24 100644 --- a/src/main/java/org/polypheny/jdbc/ProtoInterfaceClient.java +++ b/src/main/java/org/polypheny/jdbc/ProtoInterfaceClient.java @@ -73,11 +73,11 @@ public class ProtoInterfaceClient { public ProtoInterfaceClient( String host, int port, Map parameters ) throws ProtoInterfaceServiceException { try { - String mode = parameters.getOrDefault( "mode", "plain" ); - if ( mode.equals( "plain" ) ) { + String transport = parameters.getOrDefault( "transport", "plain" ); + if ( transport.equals( "plain" ) ) { con = new PlainTransport( host, port ); } else { - throw new ProtoInterfaceServiceException( "Unknown mode " + mode ); + throw new ProtoInterfaceServiceException( "Unknown mode " + transport ); } rpc = new RpcService( con ); } catch ( IOException e ) { diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyInterval.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyInterval.java index f7db6637..d6cf792d 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyInterval.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyInterval.java @@ -16,26 +16,29 @@ package org.polypheny.jdbc.nativetypes; -import java.math.BigDecimal; import org.jetbrains.annotations.NotNull; import org.polypheny.db.protointerface.proto.ProtoPolyType; public class PolyInterval extends PolyValue { - public BigDecimal value; + public long value; + public Unit unit; - public PolyInterval( BigDecimal value, ProtoPolyType intervalType ) { - super( intervalType ); - if ( !TypeUtils.INTERVAL_TYPES.contains( intervalType ) ) { - throw new RuntimeException( "Type must be an interval type." ); - } + public enum Unit { + MILLISECONDS, + MONTHS, + } + + + public PolyInterval( long value, Unit unit ) { + super( ProtoPolyType.UNSPECIFIED ); // TODO: Fix type this.value = value; } - public static PolyInterval of( BigDecimal value, ProtoPolyType intervalType ) { - return new PolyInterval( value, intervalType ); + public static PolyInterval of( long value, Unit unit ) { + return new PolyInterval( value, unit ); } @@ -50,7 +53,7 @@ public int compareTo( @NotNull PolyValue o ) { @Override public String toString() { - return value.toString() + type.toString(); + return value + " " + unit.toString().toLowerCase(); } } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyNull.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyNull.java index 172a8d69..f88c2a06 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyNull.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyNull.java @@ -289,7 +289,7 @@ public boolean isInterval() { @Override public PolyInterval asInterval() { - return PolyInterval.of( null, null ); + return PolyInterval.of( 0, null ); } diff --git a/src/main/java/org/polypheny/jdbc/nativetypes/PolyValue.java b/src/main/java/org/polypheny/jdbc/nativetypes/PolyValue.java index 8c40d09d..2f9fee4d 100644 --- a/src/main/java/org/polypheny/jdbc/nativetypes/PolyValue.java +++ b/src/main/java/org/polypheny/jdbc/nativetypes/PolyValue.java @@ -25,6 +25,7 @@ import org.polypheny.db.protointerface.proto.ProtoPolyType; import org.polypheny.jdbc.ProtoInterfaceErrors; import org.polypheny.jdbc.ProtoInterfaceServiceException; +import org.polypheny.jdbc.nativetypes.PolyInterval.Unit; import org.polypheny.jdbc.nativetypes.category.PolyBlob; import org.polypheny.jdbc.nativetypes.category.PolyNumber; import org.polypheny.jdbc.nativetypes.category.PolyTemporal; @@ -425,8 +426,12 @@ public static PolyValue fromProto( ProtoValue protoValue ) { case TIMESTAMP: return new PolyTimeStamp( protoValue.getTimestamp().getTimestamp() ); case INTERVAL: - BigDecimal value = deserializeToBigDecimal( protoValue.getInterval().getValue() ); - return new PolyInterval( value, ProtoPolyType.UNSPECIFIED ); // TODO: Fix type + switch ( protoValue.getInterval().getUnitCase() ) { + case MILLISECONDS: + return new PolyInterval( protoValue.getInterval().getMilliseconds(), Unit.MILLISECONDS ); + case MONTHS: + return new PolyInterval( protoValue.getInterval().getMonths(), Unit.MONTHS ); + } case STRING: return new PolyString( protoValue.getString().getString() ); case BINARY: diff --git a/src/main/proto/polyprism/value.proto b/src/main/proto/polyprism/value.proto index a1f0344a..f530af00 100644 --- a/src/main/proto/polyprism/value.proto +++ b/src/main/proto/polyprism/value.proto @@ -249,28 +249,13 @@ message ProtoTimestamp { } /* -Represents an interval value using a BigDecimal. +Represents an interval value. */ message ProtoInterval { - // The BigDecimal value of the interval. - ProtoBigDecimal value = 1; - enum IntervalQualifier { - UNSPECIFIED = 0; - SECOND = 1; - MINUTE_SECOND = 2; - MINUTE = 3; - HOUR_SECOND = 4; - HOUR_MINUTE = 5; - HOUR = 6; - DAY_SECOND = 7; - DAY_MINUTE = 8; - DAY_HOUR = 9; - DAY = 10; - MONTH = 11; - YEAR_MONTH = 12; - YEAR = 13; + oneof unit { + int64 milliseconds = 1; + int64 months = 2; } - IntervalQualifier qualifier = 2; } /*