Skip to content

Commit

Permalink
Add serialization of wrapped poly values
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasHafner committed Mar 20, 2024
1 parent 02344e3 commit f74a3b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
13 changes: 5 additions & 8 deletions src/main/java/org/polypheny/jdbc/jdbctypes/TypedValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.polypheny.jdbc.ProtoInterfaceServiceException;
import org.polypheny.jdbc.deserialization.UDTPrototype;
import org.polypheny.jdbc.nativetypes.PolyInterval;
import org.polypheny.jdbc.nativetypes.PolyValue;
import org.polypheny.jdbc.utils.TypedValueUtils;

public class TypedValue implements Convertible {
Expand Down Expand Up @@ -97,8 +98,8 @@ public static TypedValue fromUdtPrototype( UDTPrototype udtPrototype ) {
}


public static TypedValue fromInterval( PolyInterval interval ) {
return new TypedValue( interval, "INTERVAL" );
public static TypedValue fromPolyValue( PolyValue value ) {
return new TypedValue( value, value.type.name() );
}


Expand Down Expand Up @@ -979,9 +980,7 @@ public Object asObject() throws SQLException {
case Types.SQLXML:
return asSQLXML();
case Types.OTHER:
if ( internalType.equals( "INTERVAL" ) ) {
return value;
}
return value;
}
throw new IllegalArgumentException( "No conversion to object possible for jdbc type: " + getJdbcType() );
}
Expand Down Expand Up @@ -1051,9 +1050,7 @@ public Object asObject( Calendar calendar ) throws SQLException {
case Types.SQLXML:
return asSQLXML();
case Types.OTHER:
if ( internalType.equals( "INTERVAL" ) ) {
return value;
}
return value;
}
throw new IllegalArgumentException( "No conversion to object possible for jdbc type: " + getJdbcType() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.polypheny.jdbc.ProtoInterfaceServiceException;
import org.polypheny.jdbc.jdbctypes.TypedValue;
import org.polypheny.jdbc.nativetypes.PolyInterval;
import org.polypheny.jdbc.nativetypes.PolyValue;
import org.polypheny.jdbc.properties.DriverProperties;

public class ProtoValueSerializer {
Expand Down Expand Up @@ -98,10 +99,10 @@ public static ProtoValue serialize( TypedValue typedValue ) throws SQLException
case Types.NULL:
return serializeAsProtoNull();
case Types.OTHER:
switch ( typedValue.getInternalType() ) {
case "INTERVAL":
return serializeInterval( typedValue );
if ( !(typedValue.getValue() instanceof PolyValue) ) {
throw new RuntimeException( "Can't serialize unknown value!" );
}
return ((PolyValue) typedValue.getValue()).toProto();
break;
case Types.JAVA_OBJECT:
// TODO TH: find something useful to do here...
Expand Down

0 comments on commit f74a3b9

Please sign in to comment.