Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/proto-without-grpc' into proto-w…
Browse files Browse the repository at this point in the history
…ithout-grpc
  • Loading branch information
TobiasHafner committed Mar 20, 2024
2 parents 89d43f0 + ff6ab11 commit 5a682a7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/polypheny/jdbc/ProtoInterfaceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public class ProtoInterfaceClient {

public ProtoInterfaceClient( String host, int port, Map<String, String> 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 ) {
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/org/polypheny/jdbc/nativetypes/PolyInterval.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


Expand All @@ -50,7 +53,7 @@ public int compareTo( @NotNull PolyValue o ) {

@Override
public String toString() {
return value.toString() + type.toString();
return value + " " + unit.toString().toLowerCase();
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/polypheny/jdbc/nativetypes/PolyNull.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public boolean isInterval() {

@Override
public PolyInterval asInterval() {
return PolyInterval.of( null, null );
return PolyInterval.of( 0, null );
}


Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/polypheny/jdbc/nativetypes/PolyValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 4 additions & 19 deletions src/main/proto/polyprism/value.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
Expand Down

0 comments on commit 5a682a7

Please sign in to comment.