diff --git a/config/src/main/java/org/polypheny/db/util/PolyphenyHomeDirManager.java b/config/src/main/java/org/polypheny/db/util/PolyphenyHomeDirManager.java index d81b2d2d79..27b77e12e7 100644 --- a/config/src/main/java/org/polypheny/db/util/PolyphenyHomeDirManager.java +++ b/config/src/main/java/org/polypheny/db/util/PolyphenyHomeDirManager.java @@ -22,6 +22,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import lombok.extern.slf4j.Slf4j; /** @@ -30,6 +31,7 @@ * * All file system related operations that are specific to the PolyDBMS should be handled with this manager. */ +@Slf4j public class PolyphenyHomeDirManager { private static PolyphenyHomeDirManager INSTANCE = null; @@ -55,11 +57,12 @@ private PolyphenyHomeDirManager() { } else { pathVar = System.getProperty( "user.home" ); } - root = Path.of( pathVar, ".polypheny", getPrefix() ).toFile(); + String prefix = getPrefix(); + root = Path.of( pathVar, ".polypheny", prefix ).toFile(); - if ( !tryCreatingFolder( root ) ) { + if ( !probeCreatingFolder( root ) ) { root = new File( "." ); - if ( !tryCreatingFolder( root ) ) { + if ( !probeCreatingFolder( root ) ) { throw new RuntimeException( "Could not create root directory: .polypheny neither in: " + pathVar + " nor \".\"" ); } } @@ -85,11 +88,19 @@ public static PolyphenyHomeDirManager setModeAndGetInstance( PolyphenyMode mode private String getPrefix() { VersionCollector collector = VersionCollector.INSTANCE; - return mode == PolyphenyMode.PRODUCTION ? collector.version : collector.version + "-" + collector.branch; + + switch ( mode ) { + case PRODUCTION: + return collector.version; + case BENCHMARK: + return String.format( "%s-%s", collector.version, collector.hash ); + default: + return String.format( "%s-%s", collector.version, collector.branch ); + } } - private boolean tryCreatingFolder( File file ) { + private boolean probeCreatingFolder( File file ) { if ( file.isFile() ) { return false; } diff --git a/config/src/main/java/org/polypheny/db/util/VersionCollector.java b/config/src/main/java/org/polypheny/db/util/VersionCollector.java index 2e258d812a..a8325abbc3 100644 --- a/config/src/main/java/org/polypheny/db/util/VersionCollector.java +++ b/config/src/main/java/org/polypheny/db/util/VersionCollector.java @@ -28,6 +28,9 @@ public class VersionCollector { public static final String VERSION = "version"; public static final String BRANCH = "branch"; + + public static final String HASH = "hash"; + public static VersionCollector INSTANCE = new VersionCollector(); private final Properties versionProperties = new Properties(); @@ -36,6 +39,8 @@ public class VersionCollector { final String branch; + final String hash; + public boolean inJar = false; @@ -56,6 +61,7 @@ private VersionCollector() { } version = versionProperties.getProperty( VERSION ); branch = versionProperties.getProperty( BRANCH ); + hash = versionProperties.getProperty( HASH ); } diff --git a/core/src/main/java/org/polypheny/db/adapter/index/CoWHashIndex.java b/core/src/main/java/org/polypheny/db/adapter/index/CoWHashIndex.java index f2dde036a9..e7a6f10667 100644 --- a/core/src/main/java/org/polypheny/db/adapter/index/CoWHashIndex.java +++ b/core/src/main/java/org/polypheny/db/adapter/index/CoWHashIndex.java @@ -213,7 +213,7 @@ public Values getAsValues( PolyXid xid, AlgBuilder builder, AlgDataType rowType, @Override - Object getRaw() { + Map getRaw() { return index; } diff --git a/core/src/main/java/org/polypheny/db/adapter/index/CowMultiHashIndex.java b/core/src/main/java/org/polypheny/db/adapter/index/CowMultiHashIndex.java index c14c1f5020..cfba860779 100644 --- a/core/src/main/java/org/polypheny/db/adapter/index/CowMultiHashIndex.java +++ b/core/src/main/java/org/polypheny/db/adapter/index/CowMultiHashIndex.java @@ -226,7 +226,7 @@ public Values getAsValues( PolyXid xid, AlgBuilder builder, AlgDataType rowType, @Override - Object getRaw() { + Map, Set>> getRaw() { return index; } diff --git a/core/src/main/java/org/polypheny/db/adapter/index/Index.java b/core/src/main/java/org/polypheny/db/adapter/index/Index.java index 1f5ab2bfd9..22a960a0fc 100644 --- a/core/src/main/java/org/polypheny/db/adapter/index/Index.java +++ b/core/src/main/java/org/polypheny/db/adapter/index/Index.java @@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import lombok.Getter; import org.polypheny.db.PolyImplementation; @@ -227,7 +228,7 @@ void deleteAllPrimary( final Iterable, List>> va public abstract Values getAsValues( final PolyXid xid, AlgBuilder builder, AlgDataType rowType, final List key ); - abstract Object getRaw(); + abstract Map getRaw(); interface IndexFactory { diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/RexToLixTranslator.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/RexToLixTranslator.java index fedd794ff1..f13717ad4a 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/RexToLixTranslator.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/RexToLixTranslator.java @@ -778,7 +778,7 @@ public static Expression translateLiteral( RexLiteral literal, AlgDataType type, case INTERVAL_YEAR: case INTERVAL_YEAR_MONTH: case INTERVAL_MONTH: - value2 = literal.getValueAs( Integer.class ); + value2 = literal.getValue( Integer.class ); javaClass = int.class; break; case TIMESTAMP: @@ -793,20 +793,20 @@ public static Expression translateLiteral( RexLiteral literal, AlgDataType type, case INTERVAL_MINUTE: case INTERVAL_MINUTE_SECOND: case INTERVAL_SECOND: - value2 = literal.getValueAs( Long.class ); + value2 = literal.getValue( Long.class ); javaClass = long.class; break; case CHAR: case VARCHAR: - value2 = literal.getValueAs( String.class ); + value2 = literal.getValue( String.class ); break; case BINARY: case VARBINARY: return Expressions.new_( ByteString.class, - Expressions.constant( literal.getValueAs( byte[].class ), byte[].class ) ); + Expressions.constant( literal.getValue( byte[].class ), byte[].class ) ); case SYMBOL: - value2 = literal.getValueAs( Enum.class ); + value2 = literal.getValue( Enum.class ); javaClass = value2.getClass(); break; case ARRAY: @@ -816,20 +816,20 @@ public static Expression translateLiteral( RexLiteral literal, AlgDataType type, } else { componentType = type; } - value2 = literal.getValueAs( List.class ).stream().map( e -> translateLiteral( (RexLiteral) e, componentType, typeFactory, nullAs ) ).collect( Collectors.toList() ); + value2 = literal.getValue( List.class ).stream().map( e -> translateLiteral( (RexLiteral) e, componentType, typeFactory, nullAs ) ).collect( Collectors.toList() ); javaClass = List.class; break; case EDGE: - return literal.getValueAs( PolyEdge.class ).asExpression(); + return literal.getValue( PolyEdge.class ).asExpression(); case NODE: - return literal.getValueAs( PolyNode.class ).asExpression(); + return literal.getValue( PolyNode.class ).asExpression(); case PATH: - return literal.getValueAs( PolyPath.class ).asExpression(); + return literal.getValue( PolyPath.class ).asExpression(); case DOCUMENT: return ((PolyValue) literal.getValue()).asExpression(); default: final Primitive primitive = Primitive.ofBoxOr( javaClass ); - final Comparable value = literal.getValueAs( Comparable.class ); + final Comparable value = literal.getValue( Comparable.class ); if ( primitive != null && value instanceof Number ) { value2 = primitive.number( (Number) value ); } else { diff --git a/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJson.java b/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJson.java index e8a503e786..e2eb1a2693 100644 --- a/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJson.java +++ b/core/src/main/java/org/polypheny/db/algebra/externalize/AlgJson.java @@ -335,7 +335,7 @@ private Object toJson( RexNode node ) { return map; case LITERAL: final RexLiteral literal = (RexLiteral) node; - final Object value2 = literal.getValue2(); + final Object value2 = literal.getValue(); if ( value2 == null ) { // Special treatment for null literal because (1) we wouldn't want 'null' to be confused as an empty expression and (2) for null literals we need an explicit type. map = jsonBuilder.map(); diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdCollation.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdCollation.java index 4fa41695f4..6c01384242 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdCollation.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdCollation.java @@ -366,8 +366,8 @@ private static Ordering> comparator( AlgFieldCollation fieldCol return new Ordering<>() { @Override public int compare( List o1, List o2 ) { - final Comparable c1 = o1.get( x ).getValueAs( Comparable.class ); - final Comparable c2 = o2.get( x ).getValueAs( Comparable.class ); + final Comparable c1 = o1.get( x ).getValue(); + final Comparable c2 = o2.get( x ).getValue(); return AlgFieldCollation.compare( c1, c2, nullComparison ); } }; @@ -375,8 +375,8 @@ public int compare( List o1, List o2 ) { return new Ordering<>() { @Override public int compare( List o1, List o2 ) { - final Comparable c1 = o1.get( x ).getValueAs( Comparable.class ); - final Comparable c2 = o2.get( x ).getValueAs( Comparable.class ); + final Comparable c1 = o1.get( x ).getValue(); + final Comparable c2 = o2.get( x ).getValue(); return AlgFieldCollation.compare( c2, c1, -nullComparison ); } }; diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnUniqueness.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnUniqueness.java index 4df1ff0ada..c43605bc03 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnUniqueness.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdColumnUniqueness.java @@ -300,7 +300,7 @@ public Boolean areColumnsUnique( Values alg, AlgMetadataQuery mq, ImmutableBitSe for ( ImmutableList tuple : alg.tuples ) { for ( int column : columns ) { final RexLiteral literal = tuple.get( column ); - values.add( literal.isNull() ? NullSentinel.INSTANCE : literal.getValueAs( Comparable.class ) ); + values.add( literal.isNull() ? NullSentinel.INSTANCE : literal.getValue() ); } if ( !set.add( ImmutableList.copyOf( values ) ) ) { return false; diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdSize.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdSize.java index 8cb5678723..8ccfa66929 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdSize.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdSize.java @@ -168,7 +168,7 @@ public List averageColumnSizes( Values alg, AlgMetadataQuery mq ) { } else { d = 0; for ( ImmutableList literals : alg.getTuples() ) { - d += typeValueSize( field.getType(), literals.get( i ).getValueAs( Comparable.class ) ); + d += typeValueSize( field.getType(), literals.get( i ).getValue() ); } d /= alg.getTuples().size(); } @@ -409,7 +409,7 @@ public Double averageRexSize( RexNode node, List inputColumnSizes ) { case INPUT_REF: return inputColumnSizes.get( ((RexIndexRef) node).getIndex() ); case LITERAL: - return typeValueSize( node.getType(), ((RexLiteral) node).getValueAs( Comparable.class ) ); + return typeValueSize( node.getType(), ((RexLiteral) node).getValue() ); default: if ( node instanceof RexCall ) { RexCall call = (RexCall) node; diff --git a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdUtil.java b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdUtil.java index 757707759f..9e20c60a86 100644 --- a/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdUtil.java +++ b/core/src/main/java/org/polypheny/db/algebra/metadata/AlgMdUtil.java @@ -106,7 +106,7 @@ public static double getSelectivityValue( RexNode artificialSelectivityFuncNode RexCall call = (RexCall) artificialSelectivityFuncNode; assert call.getOperator().equals( ARTIFICIAL_SELECTIVITY_FUNC ); RexNode operand = call.getOperands().get( 0 ); - return ((RexLiteral) operand).value.asDouble().value;//.getValueAs( Double.class ); + return ((RexLiteral) operand).value.asDouble().value;//.getValue( Double.class ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/DateRangeRules.java b/core/src/main/java/org/polypheny/db/algebra/rules/DateRangeRules.java index 203e6e2b42..6a44472357 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/DateRangeRules.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/DateRangeRules.java @@ -609,7 +609,7 @@ private Calendar timestampValue( RexLiteral timeLiteral ) { return Util.calendar( timeLiteral.value.asTimeStamp().milliSinceEpoch ); case DATE: // Cast date to timestamp with local time zone - //final DateString d = timeLiteral.getValueAs( DateString.class ); + //final DateString d = timeLiteral.getValue( DateString.class ); return Util.calendar( timeLiteral.value.asDate().milliSinceEpoch ); default: throw Util.unexpected( timeLiteral.getPolyType() ); diff --git a/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java b/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java index 05660c2cd2..66a9257a02 100644 --- a/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java +++ b/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java @@ -2987,7 +2987,7 @@ public Void visitIndexRef( RexIndexRef inputRef ) { public Void visitCall( RexCall call ) { if ( call.getOperator().equals( RexBuilder.GET_OPERATOR ) ) { RexLiteral literal = (RexLiteral) call.getOperands().get( 1 ); - extraFields.add( new AlgDataTypeFieldImpl( -1L, (String) literal.getValue2(), -1, call.getType() ) ); + extraFields.add( new AlgDataTypeFieldImpl( -1L, literal.getValue().asString().value, -1, call.getType() ) ); } return super.visitCall( call ); } diff --git a/core/src/main/java/org/polypheny/db/plan/RexImplicationChecker.java b/core/src/main/java/org/polypheny/db/plan/RexImplicationChecker.java index b4f2c24e91..7a5412631b 100644 --- a/core/src/main/java/org/polypheny/db/plan/RexImplicationChecker.java +++ b/core/src/main/java/org/polypheny/db/plan/RexImplicationChecker.java @@ -226,7 +226,7 @@ public boolean isNull( RexNode node ) { ImmutableList.Builder>> usagesBuilder = ImmutableList.builder(); for ( Map.Entry> entry : firstUsageFinder.usageMap.entrySet() ) { ImmutableSet.Builder> usageBuilder = ImmutableSet.builder(); - if ( entry.getValue().usageList.size() > 0 ) { + if ( !entry.getValue().usageList.isEmpty() ) { for ( final Pair pair : entry.getValue().usageList ) { usageBuilder.add( Pair.of( entry.getKey(), pair.getValue() ) ); } diff --git a/core/src/main/java/org/polypheny/db/plan/VisitorDataContext.java b/core/src/main/java/org/polypheny/db/plan/VisitorDataContext.java index bde53a8a78..7dcdd41503 100644 --- a/core/src/main/java/org/polypheny/db/plan/VisitorDataContext.java +++ b/core/src/main/java/org/polypheny/db/plan/VisitorDataContext.java @@ -34,7 +34,6 @@ package org.polypheny.db.plan; -import java.math.BigDecimal; import java.util.List; import java.util.Map; import lombok.extern.slf4j.Slf4j; @@ -195,34 +194,34 @@ public static DataContext of( AlgDataType rowType, List visitLocalRef( RexLocalRef localRef ) { @Override public Comparable visitLiteral( RexLiteral literal ) { - return Util.first( literal.getValue4(), N ); + return Util.first( literal.getValue(), N ); } diff --git a/core/src/main/java/org/polypheny/db/rex/RexLiteral.java b/core/src/main/java/org/polypheny/db/rex/RexLiteral.java index 54f891a52a..dcba2865ea 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexLiteral.java +++ b/core/src/main/java/org/polypheny/db/rex/RexLiteral.java @@ -36,7 +36,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import com.google.gson.Gson; import java.io.PrintWriter; import java.io.StringWriter; import java.math.BigDecimal; @@ -46,16 +45,14 @@ import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; +import lombok.Getter; import lombok.Value; -import org.apache.calcite.avatica.util.ByteString; -import org.apache.calcite.avatica.util.DateTimeUtils; import org.apache.calcite.avatica.util.TimeUnit; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.constant.Kind; import org.polypheny.db.algebra.operators.OperatorName; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.nodes.Operator; -import org.polypheny.db.runtime.PolyCollections.FlatMap; import org.polypheny.db.type.PolyType; import org.polypheny.db.type.entity.PolyBigDecimal; import org.polypheny.db.type.entity.PolyString; @@ -63,11 +60,8 @@ import org.polypheny.db.type.entity.category.PolyNumber; import org.polypheny.db.util.Collation; import org.polypheny.db.util.CompositeList; -import org.polypheny.db.util.DateString; -import org.polypheny.db.util.Litmus; import org.polypheny.db.util.NlsString; import org.polypheny.db.util.Pair; -import org.polypheny.db.util.TimeString; import org.polypheny.db.util.TimestampString; import org.polypheny.db.util.Unsafe; import org.polypheny.db.util.Util; @@ -79,7 +73,7 @@ * There are several methods for creating literals in {@link RexBuilder}: {@link RexBuilder#makeLiteral(boolean)} and so forth. * * How is the value stored? In that respect, the class is somewhat of a black box. There is a {@link #getValue} method which returns the value as an object, but the type of that value is implementation detail, - * and it is best that your code does not depend upon that knowledge. It is better to use task-oriented methods such as {@link #getValue2} and {@link #toJavaString}. + * and it is best that your code does not depend upon that knowledge. It is better to use task-oriented methods such as {@link #getValue} and {@link #toJavaString}. * * The allowable types and combinations are: * @@ -161,11 +155,10 @@ * * */ +@Getter @Value public class RexLiteral extends RexNode implements Comparable { - private static final Gson gson = new Gson(); - /** * The value of this literal. Must be consistent with its type, as per {@link #valueMatchesType}. For example, you can't store an {@link Integer} value here just because you feel like it -- all numbers are * represented by a {@link BigDecimal}. But since this field is private, it doesn't really matter how the values are stored. @@ -194,13 +187,13 @@ public RexLiteral( PolyValue value, AlgDataType type, PolyType polyType ) { this.value = value; this.type = Objects.requireNonNull( type ); this.polyType = Objects.requireNonNull( polyType ); - /*if ( !valueMatchesType( value, polyType, true ) ) { + if ( !valueMatchesType( value, polyType, true ) ) { System.err.println( value ); System.err.println( value.getClass().getCanonicalName() ); System.err.println( type ); System.err.println( polyType ); throw new IllegalArgumentException(); - }*/ + } // Preconditions.checkArgument( valueMatchesType( value, typeName, true ) ); Preconditions.checkArgument( (value != null) || type.isNullable() ); Preconditions.checkArgument( polyType != PolyType.ANY ); @@ -238,7 +231,7 @@ public RexLiteral( PolyValue value, AlgDataType type, PolyType polyType, boolean * @param includeType whether the digest should include type or not * @return digest */ - public final String computeDigest( RexDigestIncludeType includeType ) { + public String computeDigest( RexDigestIncludeType includeType ) { if ( includeType == RexDigestIncludeType.OPTIONAL ) { if ( digest != null ) { // digest is initialized with OPTIONAL, so cached value matches for includeType=OPTIONAL as well @@ -270,68 +263,6 @@ RexDigestIncludeType digestIncludesType() { public static Pair convertType( PolyValue value, AlgDataType typeName ) { PolyValue converted = PolyValue.convert( value, typeName.getPolyType() ); - - - /*switch ( typeName.getPolyType() ) { - case INTEGER: - case BIGINT: - case TINYINT: - case SMALLINT: - case DECIMAL: - case DOUBLE: - case FLOAT: - case REAL: - if ( value instanceof Short ) { - return new Pair<>( new BigDecimal( (Short) value ), PolyType.DECIMAL ); - } else if ( value instanceof Byte ) { - return new Pair<>( new BigDecimal( (Byte) value ), PolyType.DECIMAL ); - } else if ( value instanceof Character ) { - return new Pair<>( new BigDecimal( (Character) value ), PolyType.DECIMAL ); - } else if ( value instanceof Integer ) { - return new Pair<>( new BigDecimal( (Integer) value ), PolyType.DECIMAL ); - } else if ( value instanceof Long ) { - return new Pair<>( new BigDecimal( (Long) value ), PolyType.DECIMAL ); - } else if ( value instanceof Float ) { - return new Pair<>( BigDecimal.valueOf( (Float) value ), PolyType.DECIMAL ); - } else if ( value instanceof Double ) { - return new Pair<>( BigDecimal.valueOf( (Double) value ), PolyType.DECIMAL ); - } - case VARCHAR: - case CHAR: - if ( value instanceof String ) { - return new Pair<>( new NlsString( (String) value, typeName.getCharset().name(), typeName.getCollation() ), PolyType.CHAR ); - } - case TIMESTAMP: - if ( value instanceof String ) { - return new Pair<>( new TimestampString( (String) value ), PolyType.TIMESTAMP ); - } else if ( value instanceof LocalDateTime ) { - final LocalDateTime dt = (LocalDateTime) value; - final TimestampString ts = new TimestampString( - dt.getYear(), - dt.getMonthValue(), - dt.getDayOfMonth(), - dt.getHour(), - dt.getMinute(), - dt.getSecond() - ); - return new Pair<>( ts, PolyType.TIMESTAMP ); - } - case TIMESTAMP_WITH_LOCAL_TIME_ZONE: - if ( value instanceof String ) { - return new Pair<>( new TimestampString( (String) value ), PolyType.TIMESTAMP_WITH_LOCAL_TIME_ZONE ); - } else if ( value instanceof LocalDateTime ) { - final LocalDateTime dt = (LocalDateTime) value; - final TimestampString ts = new TimestampString( - dt.getYear(), - dt.getMonthValue(), - dt.getDayOfMonth(), - dt.getHour(), - dt.getMinute(), - dt.getSecond() - ); - return new Pair<>( ts, PolyType.TIMESTAMP_WITH_LOCAL_TIME_ZONE ); - } - }*/ return new Pair<>( converted, typeName.getPolyType() ); } @@ -352,10 +283,6 @@ public static boolean valueMatchesType( PolyValue value, PolyType typeName, bool case INTEGER: // not allowed -- use Decimal case TINYINT: case SMALLINT: - /*if ( strict ) { - throw Util.unexpected( typeName ); - }*/ - // fall through case DECIMAL: case DOUBLE: case FLOAT: @@ -365,11 +292,9 @@ public static boolean valueMatchesType( PolyValue value, PolyType typeName, bool case DATE: return value.isDate(); case TIME: - return value.isTime(); case TIME_WITH_LOCAL_TIME_ZONE: return value.isTime(); case TIMESTAMP: - return value.isTimestamp(); case TIMESTAMP_WITH_LOCAL_TIME_ZONE: return value.isTimestamp(); case INTERVAL_YEAR: @@ -394,11 +319,7 @@ public static boolean valueMatchesType( PolyValue value, PolyType typeName, bool // fall through case BINARY: return value.isBinary(); - case VARCHAR: // not allowed -- use Char - /*if ( strict ) { - throw Util.unexpected( typeName ); - }*/ - // fall through + case VARCHAR: case CHAR: // A SqlLiteral's charset and collation are optional; not so a RexLiteral. return value.isString(); @@ -464,7 +385,7 @@ private static String toJavaString( PolyValue value, PolyType typeName, AlgDataT * @return NO_TYPE when type can be omitted, ALWAYS otherwise * @see RexLiteral#computeDigest(RexDigestIncludeType) */ - private static RexDigestIncludeType shouldIncludeType( Comparable value, AlgDataType type ) { + private static RexDigestIncludeType shouldIncludeType( PolyValue value, AlgDataType type ) { if ( type.isNullable() ) { // This means "null literal", so we require a type for it // There might be exceptions like AND(null, true) which are handled by RexCall#computeDigest @@ -477,16 +398,15 @@ private static RexDigestIncludeType shouldIncludeType( Comparable value, AlgD || type.getPolyType() == PolyType.SYMBOL ) { // We don't want false:BOOLEAN NOT NULL, so we don't print type information for non-nullable BOOLEAN and INTEGER includeType = RexDigestIncludeType.NO_TYPE; - } else if ( type.getPolyType() == PolyType.CHAR && value instanceof NlsString ) { - NlsString nlsString = (NlsString) value; + } else if ( type.getPolyType() == PolyType.CHAR && value.isString() ) { + PolyString string = value.asString(); // Ignore type information for 'Bar':CHAR(3) - if ( ((nlsString.getCharset() != null - && type.getCharset().equals( nlsString.getCharset() )) - || (nlsString.getCharset() == null + if ( ((string.getCharset() != null + && type.getCharset().equals( string.getCharset() )) + || (string.getCharset() == null && Collation.IMPLICIT.getCharset().equals( type.getCharset() ))) - && nlsString.getCollation().equals( type.getCollation() ) - && ((NlsString) value).getValue().length() == type.getPrecision() ) { + && string.value.length() == type.getPrecision() ) { includeType = RexDigestIncludeType.NO_TYPE; } else { includeType = RexDigestIncludeType.ALWAYS; @@ -505,40 +425,6 @@ private static RexDigestIncludeType shouldIncludeType( Comparable value, AlgD } - /** - * Returns whether a value is valid as a constant value, using the same criteria as {@link #valueMatchesType}. - */ - public static boolean validConstant( Object o, Litmus litmus ) { - if ( o == null - || o instanceof BigDecimal - || o instanceof NlsString - || o instanceof ByteString ) { - return litmus.succeed(); - } else if ( o instanceof List ) { - @SuppressWarnings("unchecked") List list = (List) o; - for ( Object o1 : list ) { - if ( !validConstant( o1, litmus ) ) { - return litmus.fail( "not a constant: {}", o1 ); - } - } - return litmus.succeed(); - } else if ( o instanceof Map ) { - @SuppressWarnings("unchecked") final Map map = (Map) o; - for ( Map.Entry entry : map.entrySet() ) { - if ( !validConstant( entry.getKey(), litmus ) ) { - return litmus.fail( "not a constant: {}", entry.getKey() ); - } - if ( !validConstant( entry.getValue(), litmus ) ) { - return litmus.fail( "not a constant: {}", entry.getValue() ); - } - } - return litmus.succeed(); - } else { - return litmus.fail( "not a constant: {}", o ); - } - } - - /** * Returns a list of the time units covered by an interval type such as HOUR TO SECOND. Adds MILLISECOND if the end is SECOND, to deal with fractional seconds. */ @@ -627,37 +513,38 @@ public void printAsJava( PrintWriter pw ) { * @param includeType if representation should include data type */ private static void printAsJava( PolyValue value, PrintWriter pw, PolyType typeName, boolean java, RexDigestIncludeType includeType ) { - /*switch ( typeName ) { + switch ( typeName ) { + case VARCHAR: case CHAR: - NlsString nlsString = new NlsString( value.asString().value,Charsets.UTF_8.name() , Collation.COERCIBLE ); + PolyString string = value.asString(); if ( java ) { Util.printJavaString( pw, value.asString().getValue(), true ); } else { - boolean includeCharset = (nlsString.getCharsetName() != null) && !nlsString.getCharsetName().equals( SaffronProperties.INSTANCE.defaultCharset().get() ); - pw.print( nlsString.asSql( includeCharset, false ) ); + boolean includeCharset = (string.charset != null) && !string.charset.equals( PolyValue.CHARSET ); + pw.print( string.toTypedString( includeCharset ) ); } break; case BOOLEAN: - assert value instanceof Boolean; - pw.print( ((Boolean) value).booleanValue() ); + assert value.isBoolean(); + pw.print( value.asBoolean().value ); break; case DECIMAL: - assert value instanceof BigDecimal; - pw.print( value ); + assert value.isBigDecimal(); + pw.print( value.asBigDecimal().value ); break; case DOUBLE: - assert value instanceof BigDecimal; - pw.print( Util.toScientificNotation( (BigDecimal) value ) ); + assert value.isNumber(); + pw.print( Util.toScientificNotation( value.asNumber().BigDecimalValue() ) ); break; case BIGINT: - assert value instanceof BigDecimal; - pw.print( ((BigDecimal) value).longValue() ); + assert value.isBigDecimal(); + pw.print( value.asNumber().bigDecimalValue() ); pw.print( 'L' ); break; case BINARY: - assert value instanceof ByteString; + assert value.isBinary(); pw.print( "X'" ); - pw.print( ((ByteString) value).toString( 16 ) ); + pw.print( value.asBinary().value ); pw.print( "'" ); break; case NULL: @@ -665,23 +552,23 @@ private static void printAsJava( PolyValue value, PrintWriter pw, PolyType typeN pw.print( "null" ); break; case SYMBOL: - assert value instanceof Enum; + assert value.isSymbol(); pw.print( "FLAG(" ); pw.print( value ); pw.print( ")" ); break; case DATE: - assert value instanceof DateString; + assert value.isDate(); pw.print( value ); break; case TIME: case TIME_WITH_LOCAL_TIME_ZONE: - assert value instanceof TimeString; + assert value.isTime(); pw.print( value ); break; case TIMESTAMP: case TIMESTAMP_WITH_LOCAL_TIME_ZONE: - assert value instanceof TimestampString; + assert value.isTimestamp(); pw.print( value ); break; case INTERVAL_YEAR: @@ -697,99 +584,48 @@ private static void printAsJava( PolyValue value, PrintWriter pw, PolyType typeN case INTERVAL_MINUTE: case INTERVAL_MINUTE_SECOND: case INTERVAL_SECOND: - if ( value instanceof BigDecimal ) { - pw.print( value.toString() ); - } else { - assert value == null; - pw.print( "null" ); - } + assert value.isInterval(); + pw.print( value.asInterval().getValue().toString() ); break; - case MULTISET: case ARRAY: + pw.print( value.asList().stream().map( PolyValue::toString ).collect( Collectors.toList() ) ); + break; + case MULTISET: case ROW: - @SuppressWarnings("unchecked") final List list = (List) value; - pw.print( - new AbstractList() { - @Override - public String get( int index ) { - return list.get( index ).computeDigest( includeType ); - } - - - @Override - public int size() { - return list.size(); - } - } ); + final List list = value.asList(); + pw.print( list.stream().map( PolyValue::toString ).collect( Collectors.toList() ) ); break; case MAP: - @SuppressWarnings("unchecked") final Map map = (Map) value; - pw.print( - new AbstractMap() { - @Override - public Set> entrySet() { - return map - .entrySet() - .stream() - .map( e -> new SimpleImmutableEntry<>( e.getKey().computeDigest( includeType ), e.getValue().computeDigest( includeType ) ) ) - .collect( Collectors.toSet() ); - } - } - ); + final Map map = value.asMap(); + pw.print( map.entrySet().stream().map( Object::toString ).collect( Collectors.toList() ) ); break; case NODE: - assert value instanceof PolyNode; + assert value.isNode(); pw.print( value ); break; case EDGE: - assert value instanceof PolyEdge; + assert value.isEdge(); pw.print( value ); break; case GRAPH: - assert value instanceof PolyGraph; + assert value.isGraph(); pw.print( value ); break; case PATH: - assert value instanceof PolyPath; + assert value.isPath(); pw.print( value ); break; case DOCUMENT: - assert value instanceof PolyValue; + assert value.isDocument(); pw.println( value ); break; default: assert valueMatchesType( value, typeName, true ); throw Util.needToImplement( typeName ); - }*/ - pw.println( value.asExpression() ); - } - - - private static String getCalendarFormat( PolyType typeName ) { - switch ( typeName ) { - case DATE: - return DateTimeUtils.DATE_FORMAT_STRING; - case TIME: - return DateTimeUtils.TIME_FORMAT_STRING; - case TIMESTAMP: - return DateTimeUtils.TIMESTAMP_FORMAT_STRING; - default: - throw new AssertionError( "getCalendarFormat: unknown type" ); } } - public PolyType getPolyType() { - return polyType; - } - - - @Override - public AlgDataType getType() { - return type; - } - - @Override public Kind getKind() { return Kind.LITERAL; @@ -804,337 +640,9 @@ public boolean isNull() { } - /** - * Returns the value of this literal. - * - * For backwards compatibility, returns DATE. TIME and TIMESTAMP as a {@link Calendar} value in UTC time zone. - */ - public PolyValue getValue() { - assert valueMatchesType( value, polyType, true ) : value; - if ( value == null ) { - return null; - } - switch ( polyType ) { - case TIME: - case DATE: - case TIMESTAMP: - return getValueAs( Calendar.class ); - case MAP: - //return getValueAsPolyMap(); - return null; // todo fix - default: - return value; - } - } - - - private FlatMap, Comparable> getValueAsPolyMap() { - return new FlatMap<>( ((Map) value).entrySet().stream() - .collect( Collectors.toMap( e -> e.getKey().getValueForQueryParameterizer(), e -> e.getValue().getValueForQueryParameterizer() ) ) ); - } - - - /** - * Returns the value of this literal as required by the query parameterizer. - */ - public PolyValue getValueForQueryParameterizer() { - assert valueMatchesType( value, polyType, true ) : value; - if ( value == null ) { - return null; - } - /*switch ( type.getPolyType() ) { - case TIME: - return getValueAs( TimeString.class ); - case DATE: - return getValueAs( DateString.class ); - case TIMESTAMP: - return getValueAs( TimestampString.class ); - case CHAR: - case VARCHAR: - return getValueAs( String.class ); - case BOOLEAN: - return getValueAs( Boolean.class ); - case TINYINT: - return getValueAs( Byte.class ); - case SMALLINT: - return getValueAs( Short.class ); - case INTEGER: - return getValueAs( Integer.class ); - case BIGINT: - return getValueAs( Long.class ); - case DECIMAL: - return getValueAs( BigDecimal.class ); - case FLOAT: - case REAL: - return getValueAs( Float.class ); - case DOUBLE: - return getValueAs( Double.class ); - case ARRAY: - return ComparableList.copyOf( ((List) value).stream().map( RexLiteral::getValueForQueryParameterizer ).map( v -> (T)v ).collect( Collectors.toList() ) ); - case MAP: - return getValueAsPolyMap(); - case BINARY: - case VARBINARY: - break; - case ARRAY: - break; - - default: - return value; - }*/ - return value; - - } - - - /** - * Returns the value of this literal, in the form that the calculator program builder wants it. - */ - public Object getValue2() { - if ( value == null ) { - return null; - } - switch ( polyType ) { - case CHAR: - return getValueAs( String.class ); - case DECIMAL: - case TIMESTAMP: - case TIMESTAMP_WITH_LOCAL_TIME_ZONE: - return getValueAs( Long.class ); - case DATE: - case TIME: - case TIME_WITH_LOCAL_TIME_ZONE: - return getValueAs( Integer.class ); - default: - return value; - } - } - - - /** - * Returns the value of this literal, in the form that the rex-to-lix translator wants it. - */ - public Object getValue3() { - if ( value == null ) { - return null; - } - /* - if ( Objects.requireNonNull( polyType ) == PolyType.DECIMAL ) { - assert value instanceof BigDecimal; - return value; - } - return getValue2();*/ - return null; - } - - - /** - * Returns the value of this literal, in the form that {@link RexInterpreter} wants it. - */ - public Comparable getValue4() { - if ( value == null ) { - return null; - } - switch ( polyType ) { - case TIMESTAMP: - case TIMESTAMP_WITH_LOCAL_TIME_ZONE: - return getValueAs( Long.class ); - case DATE: - case TIME: - case TIME_WITH_LOCAL_TIME_ZONE: - return getValueAs( Integer.class ); - default: - return value; - } - } - - - /** - * Returns the value of this literal as an instance of the specified class. - * - * The following SQL types allow more than one form: - * - *
    - *
  • CHAR as {@link NlsString} or {@link String}
  • - *
  • TIME as {@link TimeString}, {@link Integer} (milliseconds since midnight), {@link Calendar} (in UTC)
  • - *
  • DATE as {@link DateString}, {@link Integer} (days since 1970-01-01), {@link Calendar}
  • - *
  • TIMESTAMP as {@link TimestampString}, {@link Long} (milliseconds since 1970-01-01 00:00:00), {@link Calendar}
  • - *
  • DECIMAL as {@link BigDecimal} or {@link Long}
  • - *
- * - * Called with {@code clazz} = {@link Comparable}, returns the value in its native form. - * - * @param clazz Desired return type - * @param Return type - * @return Value of this literal in the desired type - */ - public PolyValue getValueAs( Class clazz ) { - if ( value == null ) {//|| clazz.isInstance( value ) ) { - return value;//clazz.cast( value ); - } - /*switch ( polyType ) { - case BINARY: - if ( clazz == byte[].class ) { - return clazz.cast( ((ByteString) value).getBytes() ); - } - break; - case CHAR: - if ( clazz == String.class ) { - return clazz.cast( ((NlsString) value).getValue() ); - } else if ( clazz == Character.class ) { - return clazz.cast( ((NlsString) value).getValue().charAt( 0 ) ); - } - break; - case VARCHAR: - if ( clazz == String.class ) { - return clazz.cast( ((NlsString) value).getValue() ); - } - break; - case DECIMAL: - if ( clazz == Long.class ) { - return clazz.cast( ((BigDecimal) value).unscaledValue().longValue() ); - } - // fall through - case BIGINT: - case INTEGER: - case SMALLINT: - case TINYINT: - case DOUBLE: - case REAL: - case FLOAT: - if ( clazz == Long.class ) { - return clazz.cast( ((BigDecimal) value).longValue() ); - } else if ( clazz == Integer.class ) { - return clazz.cast( ((BigDecimal) value).intValue() ); - } else if ( clazz == Short.class ) { - return clazz.cast( ((BigDecimal) value).shortValue() ); - } else if ( clazz == Byte.class ) { - return clazz.cast( ((BigDecimal) value).byteValue() ); - } else if ( clazz == Double.class ) { - return clazz.cast( ((BigDecimal) value).doubleValue() ); - } else if ( clazz == Float.class ) { - return clazz.cast( ((BigDecimal) value).floatValue() ); - } - break; - case DATE: - if ( clazz == Integer.class ) { - return clazz.cast( ((DateString) value).getDaysSinceEpoch() ); - } else if ( clazz == Calendar.class ) { - return clazz.cast( ((DateString) value).toCalendar() ); - } - break; - case TIME: - if ( clazz == Integer.class ) { - return clazz.cast( ((TimeString) value).getMillisOfDay() ); - } else if ( clazz == Calendar.class ) { - // Note: Nanos are ignored - return clazz.cast( ((TimeString) value).toCalendar() ); - } - break; - case TIME_WITH_LOCAL_TIME_ZONE: - if ( clazz == Integer.class ) { - // Milliseconds since 1970-01-01 00:00:00 - return clazz.cast( ((TimeString) value).getMillisOfDay() ); - } - break; - case TIMESTAMP: - if ( clazz == Long.class ) { - // Milliseconds since 1970-01-01 00:00:00 - return clazz.cast( ((TimestampString) value).getMillisSinceEpoch() ); - } else if ( clazz == Calendar.class ) { - // Note: Nanos are ignored - return clazz.cast( ((TimestampString) value).toCalendar() ); - } - break; - case TIMESTAMP_WITH_LOCAL_TIME_ZONE: - if ( clazz == Long.class ) { - // Milliseconds since 1970-01-01 00:00:00 - return clazz.cast( ((TimestampString) value).getMillisSinceEpoch() ); - } else if ( clazz == Calendar.class ) { - // Note: Nanos are ignored - return clazz.cast( ((TimestampString) value).toCalendar() ); - } - break; - case INTERVAL_YEAR: - case INTERVAL_YEAR_MONTH: - case INTERVAL_MONTH: - case INTERVAL_DAY: - case INTERVAL_DAY_HOUR: - case INTERVAL_DAY_MINUTE: - case INTERVAL_DAY_SECOND: - case INTERVAL_HOUR: - case INTERVAL_HOUR_MINUTE: - case INTERVAL_HOUR_SECOND: - case INTERVAL_MINUTE: - case INTERVAL_MINUTE_SECOND: - case INTERVAL_SECOND: - if ( clazz == Integer.class ) { - return clazz.cast( ((BigDecimal) value).intValue() ); - } else if ( clazz == Long.class ) { - return clazz.cast( ((BigDecimal) value).longValue() ); - } else if ( clazz == String.class ) { - return clazz.cast( intervalString( getValueAs( BigDecimal.class ).abs() ) ); - } else if ( clazz == Boolean.class ) { - // return whether negative - return clazz.cast( getValueAs( BigDecimal.class ).signum() < 0 ); - } - break; - case MAP: - if ( clazz == Map.class ) { - return clazz.cast( value ); - } - break; - case ARRAY: - if ( clazz == List.class ) { - return clazz.cast( value ); - } else if ( clazz == String.class ) { - return clazz.cast( gson.toJson( ((List) value).stream().map( RexLiteral::getValueForQueryParameterizer ).collect( Collectors.toList() ) ) ); - } - break; - case NODE: - if ( clazz == PolyNode.class ) { - return clazz.cast( value ); - } - break; - case EDGE: - if ( clazz == PolyEdge.class ) { - return clazz.cast( value ); - } - break; - case PATH: - if ( clazz == PolyPath.class ) { - return clazz.cast( value ); - } - break; - } - throw new AssertionError( "cannot convert " + polyType + " literal to " + clazz );*/ - return value; - } - - - public String getValueForFileAdapter() { - if ( value == null ) { - return null; - } - /*switch ( polyType ) { - case VARCHAR: - case CHAR: - return ((NlsString) value).getValue(); - case BOOLEAN: - return Boolean.toString( (Boolean) value ); - case DATE: - case TIME: - int i = getValueAs( Integer.class ); - return String.valueOf( i ); - case TIMESTAMP: - long l = getValueAs( Long.class ); - return String.valueOf( l ); - case BINARY: - return new String( getValueAs( byte[].class ), StandardCharsets.UTF_8 ); - default: - return value.toString(); - }*/ - return value.toString(); + @Override + public String toString() { + return super.toString(); } diff --git a/core/src/main/java/org/polypheny/db/rex/RexPermuteInputsShuttle.java b/core/src/main/java/org/polypheny/db/rex/RexPermuteInputsShuttle.java index bce4666b0c..b0816efb12 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexPermuteInputsShuttle.java +++ b/core/src/main/java/org/polypheny/db/rex/RexPermuteInputsShuttle.java @@ -101,7 +101,7 @@ public RexNode visitIndexRef( RexIndexRef local ) { @Override public RexNode visitCall( RexCall call ) { if ( call.getOperator().equals( RexBuilder.GET_OPERATOR ) ) { - final String name = (String) ((RexLiteral) call.getOperands().get( 1 )).getValue2(); + final String name = ((RexLiteral) call.getOperands().get( 1 )).getValue().asString().value; final int i = lookup( fields, name ); if ( i >= 0 ) { return RexIndexRef.of( i, fields ); diff --git a/core/src/main/java/org/polypheny/db/rex/RexProgram.java b/core/src/main/java/org/polypheny/db/rex/RexProgram.java index 1c210c01fd..558743acd7 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexProgram.java +++ b/core/src/main/java/org/polypheny/db/rex/RexProgram.java @@ -442,7 +442,7 @@ public boolean isValid( Litmus litmus, AlgNode.Context context ) { public boolean isNull( RexNode expr ) { switch ( expr.getKind() ) { case LITERAL: - return ((RexLiteral) expr).getValue2() == null; + return ((RexLiteral) expr).getValue() == null; case LOCAL_REF: RexLocalRef inputRef = (RexLocalRef) expr; return isNull( exprs.get( inputRef.index ) ); diff --git a/core/src/main/java/org/polypheny/db/rex/RexSimplify.java b/core/src/main/java/org/polypheny/db/rex/RexSimplify.java index bab7cafe96..6805b6f15d 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexSimplify.java +++ b/core/src/main/java/org/polypheny/db/rex/RexSimplify.java @@ -1131,7 +1131,7 @@ private > RexNode simplifyAnd2ForUnknownAsFalse( List> RexNode simplifyAnd2ForUnknownAsFalse( List> RexNode simplifyUsingPredicates( RexNode e, Cl || comparison.literal.getValue() == null ) { return e; } - final PolyValue v0 = comparison.literal.getValueAs( clazz ); + final PolyValue v0 = comparison.literal.getValue(); final Range range = range( comparison.kind, v0 ); final Range range2 = residue( comparison.ref, range, predicates.pulledUpPredicates, clazz ); if ( range2 == null ) { @@ -1372,7 +1372,7 @@ private > Range residue( RexNode ref, Range

r1 = range( predicate.getKind(), c1 ); if ( r0.encloses( r1 ) ) { // Given these predicates, term is always satisfied. e.g. r0 is "$0 < 10", r1 is "$0 < 5" @@ -1517,7 +1517,7 @@ private RexNode simplifyCast( RexCall e ) { switch ( operand.getKind() ) { case LITERAL: final RexLiteral literal = (RexLiteral) operand; - final PolyValue value = literal.getValueAs( Comparable.class ); + final PolyValue value = literal.getValue(); final PolyType typeName = literal.getPolyType(); // First, try to remove the cast without changing the value. diff --git a/core/src/main/java/org/polypheny/db/rex/RexUtil.java b/core/src/main/java/org/polypheny/db/rex/RexUtil.java index abc82aab34..f16314ec2e 100644 --- a/core/src/main/java/org/polypheny/db/rex/RexUtil.java +++ b/core/src/main/java/org/polypheny/db/rex/RexUtil.java @@ -202,7 +202,7 @@ public static boolean isNullLiteral( RexNode node, boolean allowCast ) { public static boolean isNull( RexNode expr ) { switch ( expr.getKind() ) { case LITERAL: - return ((RexLiteral) expr).getValue2() == null; + return ((RexLiteral) expr).getValue() == null; case CAST: return isNull( ((RexCall) expr).operands.get( 0 ) ); default: diff --git a/core/src/main/java/org/polypheny/db/type/PolySerializable.java b/core/src/main/java/org/polypheny/db/type/PolySerializable.java index f2903f6b0a..2eaec6112d 100644 --- a/core/src/main/java/org/polypheny/db/type/PolySerializable.java +++ b/core/src/main/java/org/polypheny/db/type/PolySerializable.java @@ -30,7 +30,7 @@ public interface PolySerializable { - DefiningClassLoader CLASS_LOADER = DefiningClassLoader.create( PolyPluginManager.getMainClassLoader() == null ? ClassLoader.getPlatformClassLoader() : PolyPluginManager.getMainClassLoader() ); + DefiningClassLoader CLASS_LOADER = DefiningClassLoader.create( PolyPluginManager.getMainClassLoader() == null ? PolySerializable.class.getClassLoader() : PolyPluginManager.getMainClassLoader() ); static , T> BinarySerializer buildSerializer( C clazz ) { return SerializerBuilder diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyString.java b/core/src/main/java/org/polypheny/db/type/entity/PolyString.java index d5e9ff64f2..3543d83743 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyString.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyString.java @@ -40,6 +40,7 @@ import org.jetbrains.annotations.Nullable; import org.polypheny.db.type.PolySerializable; import org.polypheny.db.type.PolyType; +import org.polypheny.db.util.Util; @Value public class PolyString extends PolyValue { @@ -199,6 +200,19 @@ public PolyString decode( BinaryInput in ) throws CorruptedDataException { } + public String toTypedString( boolean prefix ) { + StringBuilder ret = new StringBuilder(); + if ( prefix && (null != charset && charset != Charset.defaultCharset()) ) { + ret.append( "_" ); + ret.append( charset.name() ); + } + ret.append( "'" ); + ret.append( Util.replace( getValue(), "'", "''" ) ); + ret.append( "'" ); + return ret.toString(); + } + + @Override public String toString() { return value; diff --git a/core/src/main/java/org/polypheny/db/util/BsonUtil.java b/core/src/main/java/org/polypheny/db/util/BsonUtil.java index 22f836e25d..af654e08a3 100644 --- a/core/src/main/java/org/polypheny/db/util/BsonUtil.java +++ b/core/src/main/java/org/polypheny/db/util/BsonUtil.java @@ -447,28 +447,28 @@ public static Comparable getMongoComparable( PolyType finalType, RexLiteral e switch ( finalType ) { case BOOLEAN: - return el.getValueAs( Boolean.class ); + return el.getValue(); case TINYINT: - return el.getValueAs( Byte.class ); + return el.getValue(); case SMALLINT: - return el.getValueAs( Short.class ); + return el.getValue(); case INTEGER: case DATE: case TIME: - return el.getValueAs( Integer.class ); + return el.getValue(); case BIGINT: case TIMESTAMP: - return el.getValueAs( Long.class ); + return el.getValue(); case DECIMAL: - return el.getValueAs( BigDecimal.class ).toString(); + return el.getValue().toString(); case FLOAT: case REAL: - return el.getValueAs( Float.class ); + return el.getValue(); case DOUBLE: - return el.getValueAs( Double.class ); + return el.getValue(); case CHAR: case VARCHAR: - return el.getValueAs( String.class ); + return el.getValue(); case GEOMETRY: case FILE: case IMAGE: diff --git a/core/src/main/java/org/polypheny/db/util/NlsString.java b/core/src/main/java/org/polypheny/db/util/NlsString.java index 5ef62eb09b..a3c350bcf6 100644 --- a/core/src/main/java/org/polypheny/db/util/NlsString.java +++ b/core/src/main/java/org/polypheny/db/util/NlsString.java @@ -53,6 +53,7 @@ import javax.annotation.Nonnull; import lombok.Getter; import org.apache.calcite.avatica.util.ByteString; +import org.jetbrains.annotations.NotNull; import org.polypheny.db.functions.Functions; @@ -67,7 +68,7 @@ public class NlsString implements Comparable, Cloneable, Externalizab .build( new CacheLoader<>() { @Override - public String load( @Nonnull Pair key ) { + public @NotNull String load( @Nonnull Pair key ) { final Charset charset = key.right; final CharsetDecoder decoder = charset.newDecoder(); final byte[] bytes = key.left.getBytes(); diff --git a/core/src/test/java/org/polypheny/db/adapter/index/CowHashIndexTest.java b/core/src/test/java/org/polypheny/db/adapter/index/CowHashIndexTest.java index d05a10bfab..92c5efe631 100644 --- a/core/src/test/java/org/polypheny/db/adapter/index/CowHashIndexTest.java +++ b/core/src/test/java/org/polypheny/db/adapter/index/CowHashIndexTest.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.stream.Collectors; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; import org.polypheny.db.algebra.exceptions.ConstraintViolationException; import org.polypheny.db.transaction.PUID; @@ -30,17 +31,24 @@ import org.polypheny.db.type.entity.PolyInteger; import org.polypheny.db.type.entity.PolyValue; import org.polypheny.db.util.Pair; +import org.polypheny.db.util.PolyphenyHomeDirManager; +import org.polypheny.db.util.PolyphenyMode; public class CowHashIndexTest { + @BeforeClass + public static void init() { + PolyphenyHomeDirManager.setModeAndGetInstance( PolyphenyMode.TEST ); + } + @Test public void testCopyOnWriteIsolation() { // Set up CoWHashIndex idx = new CoWHashIndex( 42L, "idx_test", null, null, Collections.emptyList(), Collections.emptyList() ); PolyXid xid1 = PolyXid.generateLocalTransactionIdentifier( PUID.randomPUID( Type.NODE ), PUID.randomPUID( Type.TRANSACTION ) ); PolyXid xid2 = PolyXid.generateLocalTransactionIdentifier( PUID.randomPUID( Type.NODE ), PUID.randomPUID( Type.TRANSACTION ) ); - Assert.assertEquals( 0, ((List) idx.getRaw()).size() ); + Assert.assertEquals( 0, idx.getRaw().size() ); // Insert and delete some values as xid1 idx.insert( xid1, asPolyValues( 1, 2, 3 ), asPolyValues( 1 ) ); idx.insertAll( xid1, Arrays.asList( diff --git a/core/src/test/java/org/polypheny/db/rex/RexBuilderTest.java b/core/src/test/java/org/polypheny/db/rex/RexBuilderTest.java index c6aa1c57a2..7339866cb6 100644 --- a/core/src/test/java/org/polypheny/db/rex/RexBuilderTest.java +++ b/core/src/test/java/org/polypheny/db/rex/RexBuilderTest.java @@ -47,6 +47,7 @@ import java.util.Calendar; import java.util.TimeZone; import org.apache.calcite.avatica.util.ByteString; +import org.junit.BeforeClass; import org.junit.Test; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory; @@ -54,9 +55,12 @@ import org.polypheny.db.type.PolyType; import org.polypheny.db.type.PolyTypeFactoryImpl; import org.polypheny.db.type.entity.PolyBoolean; +import org.polypheny.db.type.entity.PolyDate; import org.polypheny.db.util.Collation; import org.polypheny.db.util.DateString; import org.polypheny.db.util.NlsString; +import org.polypheny.db.util.PolyphenyHomeDirManager; +import org.polypheny.db.util.PolyphenyMode; import org.polypheny.db.util.TimeString; import org.polypheny.db.util.TimestampString; import org.polypheny.db.util.TimestampWithTimeZoneString; @@ -68,6 +72,16 @@ */ public class RexBuilderTest { + @BeforeClass + public static void init() { + try { + PolyphenyHomeDirManager.setModeAndGetInstance( PolyphenyMode.TEST ); + } catch ( Exception e ) { + // can fail + } + + } + /** * Test RexBuilder.ensureType() */ @@ -134,20 +148,20 @@ public void testTimestampLiteral() { final TimestampString ts2 = ts.withMillis( 56 ); assertThat( ts2.toString(), is( "1969-07-21 02:56:15.056" ) ); final RexNode literal2 = builder.makeLiteral( ts2, timestampType3, false ); - assertThat( ((RexLiteral) literal2).getValueAs( TimestampString.class ).toString(), is( "1969-07-21 02:56:15.056" ) ); + assertThat( ((RexLiteral) literal2).getValue().toString(), is( "1969-07-21 02:56:15.056" ) ); // Now with nanoseconds final TimestampString ts3 = ts.withNanos( 56 ); final RexNode literal3 = builder.makeLiteral( ts3, timestampType9, false ); - assertThat( ((RexLiteral) literal3).getValueAs( TimestampString.class ).toString(), is( "1969-07-21 02:56:15" ) ); + assertThat( ((RexLiteral) literal3).getValue().toString(), is( "1969-07-21 02:56:15" ) ); final TimestampString ts3b = ts.withNanos( 2345678 ); final RexNode literal3b = builder.makeLiteral( ts3b, timestampType9, false ); - assertThat( ((RexLiteral) literal3b).getValueAs( TimestampString.class ).toString(), is( "1969-07-21 02:56:15.002" ) ); + assertThat( ((RexLiteral) literal3b).getValue().toString(), is( "1969-07-21 02:56:15.002" ) ); // Now with a very long fraction final TimestampString ts4 = ts.withFraction( "102030405060708090102" ); final RexNode literal4 = builder.makeLiteral( ts4, timestampType18, false ); - assertThat( ((RexLiteral) literal4).getValueAs( TimestampString.class ).toString(), is( "1969-07-21 02:56:15.102" ) ); + assertThat( ((RexLiteral) literal4).getValue().toString(), is( "1969-07-21 02:56:15.102" ) ); // toString assertThat( ts2.round( 1 ).toString(), is( "1969-07-21 02:56:15" ) ); @@ -172,11 +186,11 @@ private void checkTimestamp( RexNode node ) { assertThat( node.toString(), is( "1969-07-21 02:56:15" ) ); RexLiteral literal = (RexLiteral) node; assertThat( literal.getValue().isDate(), is( true ) ); - assertThat( literal.getValue2() instanceof Long, is( true ) ); - assertThat( literal.getValue3() instanceof Long, is( true ) ); - assertThat( (Long) literal.getValue2(), is( MOON ) ); - assertThat( literal.getValueAs( Calendar.class ), notNullValue() ); - assertThat( literal.getValueAs( TimestampString.class ), notNullValue() ); + assertThat( literal.getValue().isNumber(), is( true ) ); + assertThat( literal.getValue().isNumber(), is( true ) ); + assertThat( literal.getValue(), is( MOON ) ); + assertThat( literal.getValue(), notNullValue() ); + assertThat( literal.getValue(), notNullValue() ); } @@ -206,15 +220,15 @@ public void testTimestampWithLocalTimeZoneLiteral() { // Now with nanoseconds final TimestampWithTimeZoneString ts3 = ts.withNanos( 56 ); final RexNode literal3 = builder.makeLiteral( ts3.getLocalTimestampString(), timestampType9, false ); - assertThat( ((RexLiteral) literal3).getValueAs( TimestampString.class ).toString(), is( "1969-07-21 02:56:15" ) ); + assertThat( ((RexLiteral) literal3).getValue().toString(), is( "1969-07-21 02:56:15" ) ); final TimestampWithTimeZoneString ts3b = ts.withNanos( 2345678 ); final RexNode literal3b = builder.makeLiteral( ts3b.getLocalTimestampString(), timestampType9, false ); - assertThat( ((RexLiteral) literal3b).getValueAs( TimestampString.class ).toString(), is( "1969-07-21 02:56:15.002" ) ); + assertThat( ((RexLiteral) literal3b).getValue().toString(), is( "1969-07-21 02:56:15.002" ) ); // Now with a very long fraction final TimestampWithTimeZoneString ts4 = ts.withFraction( "102030405060708090102" ); final RexNode literal4 = builder.makeLiteral( ts4.getLocalTimestampString(), timestampType18, false ); - assertThat( ((RexLiteral) literal4).getValueAs( TimestampString.class ).toString(), is( "1969-07-21 02:56:15.102" ) ); + assertThat( ((RexLiteral) literal4).getValue().toString(), is( "1969-07-21 02:56:15.102" ) ); // toString assertThat( ts2.round( 1 ).toString(), is( "1969-07-21 02:56:15 PST" ) ); @@ -237,8 +251,7 @@ private void checkTimestampWithLocalTimeZone( RexNode node ) { assertThat( node.toString(), is( "1969-07-21 02:56:15:TIMESTAMP_WITH_LOCAL_TIME_ZONE(0)" ) ); RexLiteral literal = (RexLiteral) node; assertThat( literal.getValue().isTimestamp(), is( true ) ); - assertThat( literal.getValue2() instanceof Long, is( true ) ); - assertThat( literal.getValue3() instanceof Long, is( true ) ); + assertThat( literal.getValue().isTemporal(), is( true ) ); } @@ -273,19 +286,19 @@ public void testTimeLiteral() { assertThat( t2.getMillisOfDay(), is( 10575056 ) ); assertThat( t2.toString(), is( "02:56:15.056" ) ); final RexNode literal2 = builder.makeLiteral( t2, timeType3, false ); - assertThat( ((RexLiteral) literal2).getValueAs( TimeString.class ).toString(), is( "02:56:15.056" ) ); + assertThat( ((RexLiteral) literal2).getValue().toString(), is( "02:56:15.056" ) ); // Now with nanoseconds final TimeString t3 = t.withNanos( 2345678 ); assertThat( t3.getMillisOfDay(), is( 10575002 ) ); final RexNode literal3 = builder.makeLiteral( t3, timeType9, false ); - assertThat( ((RexLiteral) literal3).getValueAs( TimeString.class ).toString(), is( "02:56:15.002" ) ); + assertThat( ((RexLiteral) literal3).getValue().toString(), is( "02:56:15.002" ) ); // Now with a very long fraction final TimeString t4 = t.withFraction( "102030405060708090102" ); assertThat( t4.getMillisOfDay(), is( 10575102 ) ); final RexNode literal4 = builder.makeLiteral( t4, timeType18, false ); - assertThat( ((RexLiteral) literal4).getValueAs( TimeString.class ).toString(), is( "02:56:15.102" ) ); + assertThat( ((RexLiteral) literal4).getValue().toString(), is( "02:56:15.102" ) ); // toString assertThat( t2.round( 1 ).toString(), is( "02:56:15" ) ); @@ -310,11 +323,10 @@ private void checkTime( RexNode node ) { assertThat( node.toString(), is( "02:56:15" ) ); RexLiteral literal = (RexLiteral) node; assertThat( literal.getValue().isTime(), is( true ) ); - assertThat( literal.getValue2() instanceof Integer, is( true ) ); - assertThat( literal.getValue3() instanceof Integer, is( true ) ); - assertThat( (Integer) literal.getValue2(), is( MOON_TIME ) ); - assertThat( literal.getValueAs( Calendar.class ), notNullValue() ); - assertThat( literal.getValueAs( TimeString.class ), notNullValue() ); + assertThat( literal.getValue().isTemporal(), is( true ) ); + assertThat( literal.getValue().asNumber().intValue(), is( MOON_TIME ) ); + assertThat( literal.getValue(), notNullValue() ); + assertThat( literal.getValue(), notNullValue() ); } @@ -331,7 +343,7 @@ public void testDateLiteral() { final Calendar calendar = Util.calendar(); calendar.set( 1969, Calendar.JULY, 21 ); // one small step calendar.set( Calendar.MILLISECOND, 0 ); - checkDate( builder.makeLiteral( calendar, dateType, false ) ); + checkDate( builder.makeLiteral( PolyDate.of( calendar.getTime() ), dateType, dateType.getPolyType() ) ); // Old way #2: Provide in Integer checkDate( builder.makeLiteral( MOON_DAY, dateType, false ) ); @@ -346,16 +358,15 @@ private void checkDate( RexNode node ) { assertThat( node.toString(), is( "1969-07-21" ) ); RexLiteral literal = (RexLiteral) node; assertThat( literal.getValue().isDate(), is( true ) ); - assertThat( literal.getValue2() instanceof Integer, is( true ) ); - assertThat( literal.getValue3() instanceof Integer, is( true ) ); - assertThat( (Integer) literal.getValue2(), is( MOON_DAY ) ); - assertThat( literal.getValueAs( Calendar.class ), notNullValue() ); - assertThat( literal.getValueAs( DateString.class ), notNullValue() ); + assertThat( literal.getValue().isTemporal(), is( true ) ); + assertThat( literal.getValue().asNumber().intValue(), is( MOON_DAY ) ); + assertThat( literal.getValue(), notNullValue() ); + assertThat( literal.getValue(), notNullValue() ); } /** - * Test case for "AssertionError in {@link RexLiteral#getValue3} with null literal of type DECIMAL". + * Test case for "AssertionError in {@link RexLiteral#getValue} with null literal of type DECIMAL". */ @Test public void testDecimalLiteral() { @@ -363,7 +374,7 @@ public void testDecimalLiteral() { final AlgDataType type = typeFactory.createPolyType( PolyType.DECIMAL ); final RexBuilder builder = new RexBuilder( typeFactory ); final RexLiteral literal = builder.makeExactLiteral( null, type ); - assertThat( literal.getValue3(), nullValue() ); + assertThat( literal.getValue(), nullValue() ); } @@ -569,7 +580,7 @@ public void testBigDecimalLiteral() { private void checkBigDecimalLiteral( RexBuilder builder, String val ) { final RexLiteral literal = builder.makeExactLiteral( new BigDecimal( val ) ); - assertThat( "builder.makeExactLiteral(new BigDecimal(" + val + ")).getValueAs(BigDecimal.class).toString()", literal.getValueAs( BigDecimal.class ).toString(), is( val ) ); + assertThat( "builder.makeExactLiteral(new BigDecimal(" + val + ")).getValue(BigDecimal.class).toString()", literal.getValue().toString(), is( val ) ); } } diff --git a/dbms/build.gradle b/dbms/build.gradle index 2b1de0e9d8..d2c29e588b 100644 --- a/dbms/build.gradle +++ b/dbms/build.gradle @@ -145,6 +145,7 @@ licensee { allowDependency('javax.servlet', 'javax.servlet-api', '3.1.0') { because 'Servlet-api.jar and javax.servlet-*.jar are under the CDDL license, the original source code for this can be found at http://www.eclipse.org/jetty/downloads.php' } + allowDependency('jakarta.inject', 'jakarta.inject-api', '2.0.1') { because 'Apache 2.0 license ' } allowDependency('org.ow2.asm', 'asm', '9.4') { because 'BSD 3-Clause' } allowDependency('org.ow2.asm', 'asm-tree', '9.4') { because 'BSD 3-Clause' } @@ -311,14 +312,22 @@ def getCurrentBranch() { branch } +def getCurrentHash() { + def hash = "" + def proc = "git rev-parse --short HEAD".execute() + proc.in.eachLine { line -> hash = line } + proc.err.eachLine { line -> println line } + proc.waitFor() + hash +} + task createProperties() { doLast { - def details = getCurrentBranch(); - System.out.println("$buildDir") new File("$buildDir/version.properties").withWriter { w -> Properties p = new Properties() p['version'] = version - p['branch'] = details; + p['branch'] = getCurrentBranch() + p['hash'] = getCurrentHash() p.store w, null } // copy needed, otherwise the bean VersionController can't load the file at startup when running complete-app tests. diff --git a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java index 5c062ac608..e6d0c9a467 100644 --- a/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java +++ b/dbms/src/main/java/org/polypheny/db/PolyphenyDb.java @@ -213,6 +213,9 @@ public void runPolyphenyDb() { this.splashScreen = new SplashHelper(); } + // we have to set the mode before checking + PolyphenyHomeDirManager dirManager = PolyphenyHomeDirManager.setModeAndGetInstance( mode ); + // Check if Polypheny is already running if ( GuiUtils.checkPolyphenyAlreadyRunning() ) { if ( openUiInBrowser ) { @@ -223,31 +226,7 @@ public void runPolyphenyDb() { } // Restore content of Polypheny folder - PolyphenyHomeDirManager phdm = PolyphenyHomeDirManager.setModeAndGetInstance( mode ); - if ( phdm.checkIfExists( "_test_backup" ) && phdm.getFileIfExists( "_test_backup" ).isDirectory() ) { - File backupFolder = phdm.getFileIfExists( "_test_backup" ); - // Cleanup Polypheny folder - for ( File item : phdm.getRootPath().listFiles() ) { - if ( item.getName().equals( "_test_backup" ) ) { - continue; - } - if ( phdm.getFileIfExists( item.getName() ).isFile() ) { - phdm.deleteFile( item.getName() ); - } else { - phdm.recursiveDeleteFolder( item.getName() ); - } - } - // Restore contents from backup - for ( File item : backupFolder.listFiles() ) { - if ( phdm.checkIfExists( "_test_backup/" + item.getName() ) ) { - if ( !item.renameTo( new File( phdm.getRootPath(), item.getName() ) ) ) { - throw new GenericRuntimeException( "Unable to restore the Polypheny folder." ); - } - } - } - backupFolder.delete(); - log.info( "Restoring the data folder." ); - } + restoreHomeFolderIfNecessary( dirManager ); // Reset catalog, data and configuration if ( resetCatalog ) { @@ -262,11 +241,11 @@ public void runPolyphenyDb() { // Backup content of Polypheny folder if ( mode == PolyphenyMode.TEST || memoryCatalog ) { - if ( phdm.checkIfExists( "_test_backup" ) ) { + if ( dirManager.checkIfExists( "_test_backup" ) ) { throw new GenericRuntimeException( "Unable to backup the Polypheny folder since there is already a backup folder." ); } - File backupFolder = phdm.registerNewFolder( "_test_backup" ); - for ( File item : phdm.getRootPath().listFiles() ) { + File backupFolder = dirManager.registerNewFolder( "_test_backup" ); + for ( File item : dirManager.getRootPath().listFiles() ) { if ( item.getName().equals( "_test_backup" ) ) { continue; } @@ -505,6 +484,34 @@ public void join( final long millis ) throws InterruptedException { } + private static void restoreHomeFolderIfNecessary( PolyphenyHomeDirManager dirManager ) { + if ( dirManager.checkIfExists( "_test_backup" ) && dirManager.getFileIfExists( "_test_backup" ).isDirectory() ) { + File backupFolder = dirManager.getFileIfExists( "_test_backup" ); + // Cleanup Polypheny folder + for ( File item : dirManager.getRootPath().listFiles() ) { + if ( item.getName().equals( "_test_backup" ) ) { + continue; + } + if ( dirManager.getFileIfExists( item.getName() ).isFile() ) { + dirManager.deleteFile( item.getName() ); + } else { + dirManager.recursiveDeleteFolder( item.getName() ); + } + } + // Restore contents from backup + for ( File item : backupFolder.listFiles() ) { + if ( dirManager.checkIfExists( "_test_backup/" + item.getName() ) ) { + if ( !item.renameTo( new File( dirManager.getRootPath(), item.getName() ) ) ) { + throw new GenericRuntimeException( "Unable to restore the Polypheny folder." ); + } + } + } + backupFolder.delete(); + log.info( "Restoring the data folder." ); + } + } + + private HttpServer startHttpServer( Authenticator authenticator, TransactionManager transactionManager ) { final HttpServer httpServer = new HttpServer( transactionManager, authenticator ); Thread polyphenyUiThread = new Thread( httpServer ); diff --git a/dbms/src/main/java/org/polypheny/db/processing/shuttles/QueryParameterizer.java b/dbms/src/main/java/org/polypheny/db/processing/shuttles/QueryParameterizer.java index 0ec1254b83..f3f771baf6 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/shuttles/QueryParameterizer.java +++ b/dbms/src/main/java/org/polypheny/db/processing/shuttles/QueryParameterizer.java @@ -282,7 +282,7 @@ public AlgNode visit( LogicalRelModify initial ) { types.add( type ); values.put( idx, new ArrayList<>( ((LogicalValues) input).getTuples().size() ) ); } - values.get( idx ).add( new ParameterValue( idx, type, literal.getValueForQueryParameterizer() ) ); + values.get( idx ).add( new ParameterValue( idx, type, literal.getValue() ) ); i++; } firstRow = false; @@ -346,7 +346,7 @@ public AlgNode visitAsymmetricModify( LogicalRelModify initial ) { types.add( type ); doc.put( idx, new ArrayList<>( ((LogicalValues) input).getTuples().size() ) ); } - doc.get( idx ).add( new ParameterValue( idx, type, literal.getValueForQueryParameterizer() ) ); + doc.get( idx ).add( new ParameterValue( idx, type, literal.getValue() ) ); i++; } firstRow = false; @@ -455,7 +455,7 @@ public RexNode visitLiteral( RexLiteral literal ) { return literal; } int i = index.getAndIncrement(); - values.put( i, Collections.singletonList( new ParameterValue( i, literal.getType(), literal.getValueForQueryParameterizer() ) ) ); + values.put( i, Collections.singletonList( new ParameterValue( i, literal.getType(), literal.getValue() ) ) ); types.add( literal.getType() ); return new RexDynamicParam( literal.getType(), i ); } @@ -490,7 +490,7 @@ private PolyList createListForArrays( List operands ) { PolyList list = new PolyList<>(); for ( RexNode node : operands ) { if ( node instanceof RexLiteral ) { - list.add( ((RexLiteral) node).getValueForQueryParameterizer() ); + list.add( ((RexLiteral) node).getValue() ); } else if ( node instanceof RexCall ) { list.add( createListForArrays( ((RexCall) node).operands ) ); } else { diff --git a/information/build.gradle b/information/build.gradle index b95f927062..45592d2d85 100644 --- a/information/build.gradle +++ b/information/build.gradle @@ -56,6 +56,10 @@ compileJava { dependsOn(":config:processResources"); } +delombok { + dependsOn(":config:processResources"); +} + /** * JARs */ diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailSort.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailSort.java index 85e90ea983..5dcd991978 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailSort.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/algebra/CottontailSort.java @@ -130,7 +130,7 @@ private static Expression numberBuilderBuilder( RexNode node ) { Expression expr; if ( node instanceof RexLiteral ) { - expr = Expressions.constant( ((RexLiteral) node).getValueAs( Integer.class ) ); + expr = Expressions.constant( ((RexLiteral) node).getValue() ); } else if ( node instanceof RexDynamicParam ) { expr = Expressions.call( dynamicParameterMap_, BuiltInMethod.MAP_GET.method, Expressions.constant( ((RexDynamicParam) node).getIndex() ) ); } else { diff --git a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/util/CottontailTypeUtil.java b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/util/CottontailTypeUtil.java index 27ca63020a..13b657b58b 100644 --- a/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/util/CottontailTypeUtil.java +++ b/plugins/cottontail-adapter/src/main/java/org/polypheny/db/adapter/cottontail/util/CottontailTypeUtil.java @@ -25,7 +25,6 @@ import java.util.Map.Entry; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; -import org.apache.calcite.avatica.util.ByteString; import org.apache.calcite.linq4j.tree.BlockBuilder; import org.apache.calcite.linq4j.tree.ConstantExpression; import org.apache.calcite.linq4j.tree.Expression; @@ -200,38 +199,38 @@ public static Expression rexLiteralToDataExpression( RexLiteral rexLiteral, Poly } else { switch ( actualType ) { case BOOLEAN: - constantExpression = Expressions.constant( rexLiteral.getValueAs( Boolean.class ) ); + constantExpression = Expressions.constant( rexLiteral.getValue() ); break; case INTEGER: - constantExpression = Expressions.constant( rexLiteral.getValueAs( Integer.class ) ); + constantExpression = Expressions.constant( rexLiteral.getValue() ); break; case BIGINT: - constantExpression = Expressions.constant( rexLiteral.getValueAs( Long.class ) ); + constantExpression = Expressions.constant( rexLiteral.getValue() ); break; case DOUBLE: - constantExpression = Expressions.constant( rexLiteral.getValueAs( Double.class ) ); + constantExpression = Expressions.constant( rexLiteral.getValue() ); break; case REAL: case FLOAT: - constantExpression = Expressions.constant( rexLiteral.getValueAs( Float.class ) ); + constantExpression = Expressions.constant( rexLiteral.getValue() ); break; case VARCHAR: case CHAR: case JSON: - constantExpression = Expressions.constant( rexLiteral.getValueAs( String.class ) ); + constantExpression = Expressions.constant( rexLiteral.getValue() ); break; case DATE: case TIME: - constantExpression = Expressions.constant( rexLiteral.getValueAs( Integer.class ) ); + constantExpression = Expressions.constant( rexLiteral.getValue() ); break; case TIMESTAMP: - constantExpression = Expressions.constant( rexLiteral.getValueAs( Long.class ) ); + constantExpression = Expressions.constant( rexLiteral.getValue() ); break; case TINYINT: - constantExpression = Expressions.constant( rexLiteral.getValueAs( Byte.class ) ); + constantExpression = Expressions.constant( rexLiteral.getValue() ); break; case SMALLINT: - constantExpression = Expressions.constant( rexLiteral.getValueAs( Short.class ) ); + constantExpression = Expressions.constant( rexLiteral.getValue() ); break; case DECIMAL: BigDecimal bigDecimal = rexLiteral.value.asNumber().BigDecimalValue(); @@ -494,34 +493,34 @@ private static List arrayCallToList( List operands, PolyType in private static Object rexLiteralToJavaClass( RexLiteral rexLiteral, PolyType actualType ) { switch ( actualType ) { case BOOLEAN: - return rexLiteral.getValueAs( Boolean.class ); + return rexLiteral.getValue(); case INTEGER: - return rexLiteral.getValueAs( Integer.class ); + return rexLiteral.getValue(); case BIGINT: - return rexLiteral.getValueAs( Long.class ); + return rexLiteral.getValue(); case DOUBLE: - return rexLiteral.getValueAs( Double.class ); + return rexLiteral.getValue(); case REAL: case FLOAT: - return rexLiteral.getValueAs( Float.class ); + return rexLiteral.getValue(); case VARCHAR: case CHAR: case JSON: - return rexLiteral.getValueAs( String.class ); + return rexLiteral.getValue(); case TIMESTAMP: - return rexLiteral.getValueAs( Long.class ); + return rexLiteral.getValue(); case DATE: case TIME: - return rexLiteral.getValueAs( Integer.class ); + return rexLiteral.getValue(); case DECIMAL: - return rexLiteral.getValueAs( BigDecimal.class ); + return rexLiteral.getValue(); case VARBINARY: case BINARY: - return rexLiteral.getValueAs( ByteString.class ); + return rexLiteral.getValue(); case TINYINT: - return rexLiteral.getValueAs( Byte.class ); + return rexLiteral.getValue(); case SMALLINT: - return rexLiteral.getValueAs( Short.class ); + return rexLiteral.getValue(); default: throw new GenericRuntimeException( "Type " + actualType + " is not supported by the cottontail adapter." ); } @@ -600,7 +599,7 @@ private static Expression knnCallVector( RexNode node, ParameterExpression dynam */ private static Expression knnCallDistance( RexNode node, ParameterExpression dynamicParamMap ) { if ( node instanceof RexLiteral ) { - return Expressions.constant( ((RexLiteral) node).getValue2() ); + return Expressions.constant( ((RexLiteral) node).getValue() ); } else if ( node instanceof RexDynamicParam ) { RexDynamicParam dynamicParam = (RexDynamicParam) node; return Expressions.call( dynamicParamMap, BuiltInMethod.MAP_GET.method, @@ -623,20 +622,20 @@ public static SqlLiteral defaultValueParser( LogicalDefaultValue logicalDefaultV literal = Boolean.parseBoolean( logicalDefaultValue.value.toJson() ); break; case INTEGER: - literal = SqlLiteral.createExactNumeric( logicalDefaultValue.value.toJson(), ParserPos.ZERO ).getValueAs( Integer.class ); + literal = SqlLiteral.createExactNumeric( logicalDefaultValue.value.toJson(), ParserPos.ZERO ).getValue( Integer.class ); break; case DECIMAL: - literal = SqlLiteral.createExactNumeric( logicalDefaultValue.value.toJson(), ParserPos.ZERO ).getValueAs( BigDecimal.class ); + literal = SqlLiteral.createExactNumeric( logicalDefaultValue.value.toJson(), ParserPos.ZERO ).getValue( BigDecimal.class ); break; case BIGINT: - literal = SqlLiteral.createExactNumeric( logicalDefaultValue.value.toJson(), ParserPos.ZERO ).getValueAs( Long.class ); + literal = SqlLiteral.createExactNumeric( logicalDefaultValue.value.toJson(), ParserPos.ZERO ).getValue( Long.class ); break; case REAL: case FLOAT: - literal = SqlLiteral.createApproxNumeric( logicalDefaultValue.value.toJson(), ParserPos.ZERO ).getValueAs( Float.class ); + literal = SqlLiteral.createApproxNumeric( logicalDefaultValue.value.toJson(), ParserPos.ZERO ).getValue( Float.class ); break; case DOUBLE: - literal = SqlLiteral.createApproxNumeric( logicalDefaultValue.value.toJson(), ParserPos.ZERO ).getValueAs( Double.class ); + literal = SqlLiteral.createApproxNumeric( logicalDefaultValue.value.toJson(), ParserPos.ZERO ).getValue( Double.class ); break; case VARCHAR: literal = logicalDefaultValue.value; diff --git a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvFilterableTable.java b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvFilterableTable.java index beddbede28..e7412e0577 100644 --- a/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvFilterableTable.java +++ b/plugins/csv-adapter/src/main/java/org/polypheny/db/adapter/csv/CsvFilterableTable.java @@ -91,7 +91,7 @@ private boolean addFilter( RexNode filter, Object[] filterValues ) { if ( left instanceof RexIndexRef && right instanceof RexLiteral ) { final int index = ((RexIndexRef) left).getIndex(); if ( filterValues[index] == null ) { - filterValues[index] = ((RexLiteral) right).getValue2().toString(); + filterValues[index] = ((RexLiteral) right).getValue().toString(); return true; } } diff --git a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelFilterableTable.java b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelFilterableTable.java index dc8575408a..1c29d153a7 100644 --- a/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelFilterableTable.java +++ b/plugins/excel-adapter/src/main/java/org/polypheny/db/adapter/excel/ExcelFilterableTable.java @@ -81,7 +81,7 @@ private boolean addFilter( RexNode filter, Object[] filterValues ) { if ( left instanceof RexIndexRef && right instanceof RexLiteral ) { final int index = ((RexIndexRef) left).getIndex(); if ( filterValues[index] == null ) { - filterValues[index] = ((RexLiteral) right).getValue2().toString(); + filterValues[index] = ((RexLiteral) right).getValue().toString(); return true; } } diff --git a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/AlgToSqlConverter.java b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/AlgToSqlConverter.java index b4990b0029..3255d24922 100644 --- a/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/AlgToSqlConverter.java +++ b/plugins/jdbc-adapter-framework/src/main/java/org/polypheny/db/adapter/jdbc/rel2sql/AlgToSqlConverter.java @@ -565,7 +565,7 @@ public Result visit( Match e ) { final SqlNode after; if ( e.getAfter() instanceof RexLiteral ) { - SqlMatchRecognize.AfterOption value = (SqlMatchRecognize.AfterOption) ((RexLiteral) e.getAfter()).getValue2(); + SqlMatchRecognize.AfterOption value = (SqlMatchRecognize.AfterOption) ((RexLiteral) e.getAfter()).getValue().asSymbol().value; after = SqlLiteral.createSymbol( value, POS ); } else { RexCall call = (RexCall) e.getAfter(); diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/bson/BsonFunctionHelper.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/bson/BsonFunctionHelper.java index 9e4f9ac87e..ff384423d8 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/bson/BsonFunctionHelper.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/bson/BsonFunctionHelper.java @@ -77,7 +77,7 @@ public class BsonFunctionHelper extends BsonDocument { public static BsonDocument getFunction( RexCall call, AlgDataType rowType, Implementor implementor ) { String function; if ( call.operands.size() == 3 && call.operands.get( 2 ) instanceof RexLiteral ) { - Object funcName = ((RexLiteral) call.operands.get( 2 )).getValue3(); + Object funcName = ((RexLiteral) call.operands.get( 2 )).getValue(); function = getUsedFunction( funcName ); return new BsonDocument().append( diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoFilter.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoFilter.java index eba9040b8d..5c611624a0 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoFilter.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoFilter.java @@ -1134,7 +1134,7 @@ private boolean translateDocValue( String op, RexCall left, RexNode right ) { if ( names.operands.size() > 0 ) { mergedName += "." + names.operands .stream() - .map( name -> ((RexLiteral) name).getValueAs( String.class ) ) + .map( name -> ((RexLiteral) name).getValue( String.class ) ) .collect( Collectors.joining( "." ) ); } diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoRules.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoRules.java index f17c74ee30..364c9c9da8 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoRules.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoRules.java @@ -129,16 +129,14 @@ static String isItem( RexCall call ) { if ( op0 instanceof RexIndexRef && ((RexIndexRef) op0).getIndex() == 0 && op1 instanceof RexLiteral - && ((RexLiteral) op1).getValue2() instanceof String ) { - return (String) ((RexLiteral) op1).getValue2(); + && ((RexLiteral) op1).getValue().isString() ) { + return ((RexLiteral) op1).getValue().asString().value; } /*if ( op0 instanceof RexInputRef && op1 instanceof RexDynamicParam ) { return new BsonDynamic( (RexDynamicParam) op1 ).toJson(); }*/ - if ( op0.getType().getPolyType() == PolyType.ARRAY & op1 instanceof RexLiteral && op0 instanceof RexIndexRef ) { - return null; - } + op0.getType().getPolyType(); return null; } @@ -200,7 +198,7 @@ public static Pair getAddFields( RexCall call, AlgDataType rowT assert call.operands.get( 0 ) instanceof RexIndexRef; assert call.operands.get( 1 ) instanceof RexLiteral; String field = rowType.getFieldNames().get( ((RexIndexRef) call.operands.get( 0 )).getIndex() ); - field += "." + ((RexLiteral) call.operands.get( 1 )).getValueAs( String.class ); + field += "." + ((RexLiteral) call.operands.get( 1 )).getValue(); return new Pair<>( field, call.operands.get( 2 ) ); } diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoTableModify.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoTableModify.java index 5dd3f311f1..6b4a08631a 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoTableModify.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoTableModify.java @@ -260,7 +260,7 @@ private BsonDocument getRenameUpdate( List keys, String parentKey, RexCa assert keys.size() == call.operands.size(); int pos = 0; for ( String key : keys ) { - doc.put( key, new BsonString( parentKey + "." + ((RexLiteral) call.operands.get( pos )).getValueAs( String.class ) ) ); + doc.put( key, new BsonString( parentKey + "." + ((RexLiteral) call.operands.get( pos )).getValue() ) ); pos++; } @@ -329,7 +329,7 @@ private List getDocUpdateKey( RexIndexRef row, RexCall subfield, MongoRo return subfield .operands .stream() - .map( n -> ((RexLiteral) n).getValueAs( String.class ) ) + .map( n -> ((RexLiteral) n).getValue() ) .map( n -> name + "." + n ) .collect( Collectors.toList() ); } @@ -355,7 +355,7 @@ private BsonValue visitCall( Implementor implementor, RexCall call, Kind op, Pol } else if ( operand instanceof RexCall ) { array.add( visitCall( implementor, (RexCall) operand, ((RexCall) operand).op.getKind(), type ) ); } else if ( operand.getKind() == Kind.LITERAL ) { - array.add( BsonUtil.getAsBson( ((RexLiteral) operand).getValueAs( BsonUtil.getClassFromType( type ) ), type, bucket ) ); + array.add( BsonUtil.getAsBson( ((RexLiteral) operand).getValue(), type, bucket ) ); } else if ( operand.getKind() == Kind.DYNAMIC_PARAM ) { array.add( new BsonDynamic( (RexDynamicParam) operand ) ); } else { diff --git a/plugins/mql-language/src/test/java/org/polypheny/db/mql/mql2alg/dql/Mql2AlgFindTest.java b/plugins/mql-language/src/test/java/org/polypheny/db/mql/mql2alg/dql/Mql2AlgFindTest.java index 86959c50b9..c4c80c8e2a 100644 --- a/plugins/mql-language/src/test/java/org/polypheny/db/mql/mql2alg/dql/Mql2AlgFindTest.java +++ b/plugins/mql-language/src/test/java/org/polypheny/db/mql/mql2alg/dql/Mql2AlgFindTest.java @@ -630,7 +630,7 @@ private void testJsonExists( RexCall condition, String key ) { assertRexCall( condition, 1 ) .operands .stream() - .map( e -> ((RexLiteral) e).getValueAs( String.class ) ) + .map( e -> ((RexLiteral) e).getValue() ) .collect( Collectors.toList() ) ); } @@ -680,7 +680,7 @@ private void testJsonCommon( String key, RexCall jsonApi, List excludes assertTrue( jsonApi.operands.get( 1 ).isA( Kind.LITERAL ) ); RexLiteral cond = (RexLiteral) jsonApi.operands.get( 1 ); - assertEquals( key == null ? "strict $" : "strict $." + key, cond.getValueAs( String.class ) ); + assertEquals( key == null ? "strict $" : "strict $." + key, cond.getValue() ); } @@ -695,7 +695,7 @@ private void testJsonExpressionExcludes( RexCall jsonExpr, List excludes assertEquals( Kind.ARRAY_VALUE_CONSTRUCTOR, excluded.op.getKind() ); assertEquals( excludes.size(), excluded.operands.size() ); List names = excluded.operands.stream() - .map( e -> ((RexLiteral) e).getValueAs( String.class ) ) + .map( e -> ((RexLiteral) e).getValue() ) .collect( Collectors.toList() ); assertEquals( names, excludes ); } @@ -710,7 +710,7 @@ private void testJsonExpression( RexCall jsonExpr ) { private void testCastLiteral( RexNode node, Object value, Class clazz ) { assertTrue( node.isA( Kind.LITERAL ) ); - assertEquals( value, ((RexLiteral) node).getValueAs( clazz ) ); + assertEquals( value, ((RexLiteral) node).getValue() ); } diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/NeoUtil.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/NeoUtil.java index 39b3104c79..92063bb36d 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/NeoUtil.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/NeoUtil.java @@ -273,7 +273,7 @@ static PolyType getComponentTypeOrParent( AlgDataType type ) { } static String rexAsString( RexLiteral literal, String mappingLabel, boolean isLiteral ) { - Object ob = literal.getValueForQueryParameterizer(); + Object ob = literal.getValue(); if ( ob == null ) { return null; } @@ -303,12 +303,12 @@ static String rexAsString( RexLiteral literal, String mappingLabel, boolean isLi case INTERVAL_SECOND: case TIMESTAMP: case TIMESTAMP_WITH_LOCAL_TIME_ZONE: - return literal.getValueAs( Long.class ).toString(); + return literal.getValue().toString(); case DECIMAL: case FLOAT: case REAL: case DOUBLE: - return literal.getValueAs( Double.class ).toString(); + return literal.getValue().toString(); case CHAR: case VARCHAR: if ( isLiteral ) { diff --git a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/Translator.java b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/Translator.java index 2e0ab99631..c98aaa1489 100644 --- a/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/Translator.java +++ b/plugins/neo4j-adapter/src/main/java/org/polypheny/db/adapter/neo4j/util/Translator.java @@ -246,7 +246,7 @@ private String handleSetProperty( RexCall call ) { RexLiteral rex = (RexLiteral) call.operands.get( 2 ); String literal = NeoUtil.rexAsString( rex, null, true ); if ( PolyType.STRING_TYPES.contains( rex.getType().getPolyType() ) ) { - literal = String.format( "'%s'", rex.getValueAs( String.class ) ); + literal = String.format( "'%s'", rex.getValue() ); } return String.format( "%s.%s = %s", identifier, key, literal ); } diff --git a/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexExecutorTest.java b/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexExecutorTest.java index 754cde2492..26b91d2e58 100644 --- a/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexExecutorTest.java +++ b/plugins/sql-language/src/test/java/org/polypheny/db/sql/RexExecutorTest.java @@ -154,7 +154,7 @@ public void testConstant() throws Exception { executor.reduce( rexBuilder, ImmutableList.of( ten ), reducedValues ); assertThat( reducedValues.size(), equalTo( 1 ) ); assertThat( reducedValues.get( 0 ), instanceOf( RexLiteral.class ) ); - assertThat( ((RexLiteral) reducedValues.get( 0 )).getValue2(), equalTo( (Object) 10L ) ); + assertThat( ((RexLiteral) reducedValues.get( 0 )).getValue(), equalTo( (Object) 10L ) ); } ); } @@ -189,7 +189,7 @@ private void checkConstant( final Object operand, final Function