From 121e262d26d391ce0caf7a1721cc5e9b3f10a184 Mon Sep 17 00:00:00 2001 From: datomo Date: Tue, 31 Oct 2023 22:18:42 +0100 Subject: [PATCH] fixed parsing of certain binaries, filestore tests --- .../org/polypheny/db/adapter/DataContext.java | 2 +- .../org/polypheny/db/adapter/Scannable.java | 4 +- .../catalogs/LogicalRelationalCatalog.java | 6 +- .../entity/logical/LogicalTableWrapper.java | 2 + .../impl/logical/RelationalCatalog.java | 6 +- .../db/plan/volcano/VolcanoPlanner.java | 29 --------- .../polypheny/db/type/entity/PolyBinary.java | 8 ++- .../polypheny/db/type/entity/PolyValue.java | 2 +- .../java/org/polypheny/db/util/BitString.java | 9 +-- .../org/polypheny/db/ddl/DdlManagerImpl.java | 31 ++++++---- .../db/partition/FrequencyMapImpl.java | 2 +- .../db/processing/AbstractQueryProcessor.java | 2 +- .../org/polypheny/db/avatica/DbmsMeta.java | 5 ++ .../polypheny/db/adapter/file/Condition.java | 62 +++++++++---------- .../polypheny/db/adapter/file/FileAlg.java | 4 +- .../db/adapter/file/FileEnumerator.java | 35 +++++------ .../db/adapter/file/FileModifier.java | 3 +- .../polypheny/db/adapter/file/FilePlugin.java | 2 +- .../db/adapter/file/FileStoreSchema.java | 6 +- .../org/polypheny/db/adapter/file/Value.java | 11 ---- .../adapter/file/algebra/FileTableModify.java | 9 ++- .../db/adapter/file/source/QfsEnumerator.java | 5 +- .../db/adapter/file/util/FileUtil.java | 4 +- .../sql/language/SqlBinaryStringLiteral.java | 2 +- .../polypheny/db/sql/language/SqlLiteral.java | 7 +-- .../sql2alg/SqlNodeToRexConverterImpl.java | 11 +--- 26 files changed, 116 insertions(+), 153 deletions(-) diff --git a/core/src/main/java/org/polypheny/db/adapter/DataContext.java b/core/src/main/java/org/polypheny/db/adapter/DataContext.java index 02132b28b3..9caf7e2ab1 100644 --- a/core/src/main/java/org/polypheny/db/adapter/DataContext.java +++ b/core/src/main/java/org/polypheny/db/adapter/DataContext.java @@ -94,7 +94,7 @@ default void resetParameterValues() { throw new UnsupportedOperationException(); } - default Object getParameterValue( long index ) { + default PolyValue getParameterValue( long index ) { if ( getParameterValues().size() != 1 ) { throw new GenericRuntimeException( "Illegal number of parameter sets" ); } diff --git a/core/src/main/java/org/polypheny/db/adapter/Scannable.java b/core/src/main/java/org/polypheny/db/adapter/Scannable.java index 5b08af520c..3d56a6e91c 100644 --- a/core/src/main/java/org/polypheny/db/adapter/Scannable.java +++ b/core/src/main/java/org/polypheny/db/adapter/Scannable.java @@ -68,8 +68,8 @@ static PhysicalTable createSubstitutionTable( Scannable scannable, Context conte AllocationColumn alloc = new AllocationColumn( logical.namespaceId, allocSubTable.placementId, allocSubTable.logicalId, column.id, PlacementType.AUTOMATIC, i++, allocation.adapterId ); allocColumns.add( alloc ); } - - scannable.createTable( context, LogicalTableWrapper.of( table, columns ), AllocationTableWrapper.of( allocSubTable, allocColumns ) ); + // we use first as pk + scannable.createTable( context, LogicalTableWrapper.of( table, columns, List.of( columns.get( 0 ).id ) ), AllocationTableWrapper.of( allocSubTable, allocColumns ) ); return scannable.getCatalog().getPhysicalsFromAllocs( allocSubTable.id ).get( 0 ).unwrap( PhysicalTable.class ); } diff --git a/core/src/main/java/org/polypheny/db/catalog/catalogs/LogicalRelationalCatalog.java b/core/src/main/java/org/polypheny/db/catalog/catalogs/LogicalRelationalCatalog.java index aaa25a129f..cc7e424c91 100644 --- a/core/src/main/java/org/polypheny/db/catalog/catalogs/LogicalRelationalCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/catalogs/LogicalRelationalCatalog.java @@ -193,8 +193,9 @@ public interface LogicalRelationalCatalog extends LogicalCatalog { * * @param tableId The id of the table * @param columnIds The id of key which will be part of the primary keys + * @return */ - void addPrimaryKey( long tableId, List columnIds ); + LogicalTable addPrimaryKey( long tableId, List columnIds ); /** @@ -216,8 +217,9 @@ public interface LogicalRelationalCatalog extends LogicalCatalog { * @param tableId The id of the table * @param constraintName The name of the constraint * @param columnIds A list of column ids + * @return */ - void addUniqueConstraint( long tableId, String constraintName, List columnIds ); + LogicalTable addUniqueConstraint( long tableId, String constraintName, List columnIds ); /** * Deletes the specified primary key (including the entry in the key table). If there is an index on this key, make sure to delete it first. diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalTableWrapper.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalTableWrapper.java index d6aa2614be..db10d48b46 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalTableWrapper.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalTableWrapper.java @@ -26,4 +26,6 @@ public class LogicalTableWrapper { public List columns; + public List pkIds; + } diff --git a/core/src/main/java/org/polypheny/db/catalog/impl/logical/RelationalCatalog.java b/core/src/main/java/org/polypheny/db/catalog/impl/logical/RelationalCatalog.java index 28bc7a53d9..e02f802ec0 100644 --- a/core/src/main/java/org/polypheny/db/catalog/impl/logical/RelationalCatalog.java +++ b/core/src/main/java/org/polypheny/db/catalog/impl/logical/RelationalCatalog.java @@ -366,7 +366,7 @@ public void deleteDefaultValue( long columnId ) { @Override - public void addPrimaryKey( long tableId, List columnIds ) { + public LogicalTable addPrimaryKey( long tableId, List columnIds ) { if ( columnIds.stream().anyMatch( id -> columns.get( id ).nullable ) ) { throw new GenericRuntimeException( "Primary key is not allowed to use nullable columns." ); } @@ -390,6 +390,7 @@ public void addPrimaryKey( long tableId, List columnIds ) { long keyId = getOrAddKey( tableId, columnIds, EnforcementTime.ON_QUERY ); setPrimaryKey( tableId, keyId ); change(); + return tables.get( tableId ); } @@ -500,7 +501,7 @@ public void addForeignKey( long tableId, List columnIds, long referencesTa @Override - public void addUniqueConstraint( long tableId, String constraintName, List columnIds ) { + public LogicalTable addUniqueConstraint( long tableId, String constraintName, List columnIds ) { long keyId = getOrAddKey( tableId, columnIds, EnforcementTime.ON_QUERY ); // Check if there is already a unique constraint List logicalConstraints = constraints.values().stream() @@ -514,6 +515,7 @@ public void addUniqueConstraint( long tableId, String constraintName, List constraints.put( id, new LogicalConstraint( id, keyId, ConstraintType.UNIQUE, constraintName, Objects.requireNonNull( keys.get( keyId ) ) ) ); change(); } + return tables.get( tableId ); } diff --git a/core/src/main/java/org/polypheny/db/plan/volcano/VolcanoPlanner.java b/core/src/main/java/org/polypheny/db/plan/volcano/VolcanoPlanner.java index 6b588785bc..566becf85b 100644 --- a/core/src/main/java/org/polypheny/db/plan/volcano/VolcanoPlanner.java +++ b/core/src/main/java/org/polypheny/db/plan/volcano/VolcanoPlanner.java @@ -1261,35 +1261,6 @@ public void addRuleDuringRuntime( AlgOptRule rule ) { } } - - /*AlgVisitor visitor = new AlgVisitor() { - final Set visitedSubsets = new HashSet<>(); - - - @Override - public void visit( AlgNode node, int ordinal, AlgNode parent ) { - if ( node instanceof AlgSubset ) { - AlgSubset subset = (AlgSubset) node; - - if ( visitedSubsets.contains( subset ) ) { - return; - } - - visitedSubsets.add( subset ); - - int i = 0; - for ( AlgNode alg : subset.set.algs ) { - visit( alg, i++, subset ); - } - } else { - if ( operand.matches( node ) ) { - matches.add( Pair.of( node, (AlgSubset) parent ) ); - } - super.visit( node, ordinal, parent ); - } - } - }; - visitor.go( root );*/ for ( Pair pair : matches ) { fireRules( pair.left, true ); } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyBinary.java b/core/src/main/java/org/polypheny/db/type/entity/PolyBinary.java index e0e4e40646..255f49ad5a 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyBinary.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyBinary.java @@ -20,9 +20,11 @@ import lombok.Value; import org.apache.calcite.avatica.util.ByteString; import org.apache.calcite.linq4j.tree.Expression; +import org.apache.calcite.linq4j.tree.Expressions; import org.jetbrains.annotations.NotNull; import org.polypheny.db.type.PolySerializable; import org.polypheny.db.type.PolyType; +import org.polypheny.db.util.BitString; import org.polypheny.db.util.ConversionUtil; @EqualsAndHashCode(callSuper = true) @@ -88,7 +90,7 @@ public String toHexString() { @Override public Expression asExpression() { - return null; + return Expressions.call( PolyBinary.class, "of", Expressions.constant( value.getBytes() ) ); } @@ -100,12 +102,12 @@ public PolySerializable copy() { @Override public String toString() { - return value.toBase64String(); + return value.toString(); } public int getBitCount() { - return value.getBytes().length; + return BitString.createFromBytes( value.getBytes() ).getBitCount(); } diff --git a/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java b/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java index a3af9a5f21..ae67d33282 100644 --- a/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java +++ b/core/src/main/java/org/polypheny/db/type/entity/PolyValue.java @@ -229,7 +229,7 @@ public static Function1 getPolyToJava( AlgDataType type, bool case VIDEO: return o -> o.asBlob().asByteArray(); default: - throw new org.apache.commons.lang3.NotImplementedException( "meta" ); + throw new NotImplementedException( "meta" ); } } diff --git a/core/src/main/java/org/polypheny/db/util/BitString.java b/core/src/main/java/org/polypheny/db/util/BitString.java index d36e209144..4e4309037e 100644 --- a/core/src/main/java/org/polypheny/db/util/BitString.java +++ b/core/src/main/java/org/polypheny/db/util/BitString.java @@ -36,6 +36,7 @@ import java.math.BigInteger; import java.util.List; +import lombok.Getter; /** @@ -51,6 +52,7 @@ public class BitString { private final String bits; + @Getter private final int bitCount; @@ -95,11 +97,6 @@ public String toString() { } - public int getBitCount() { - return bitCount; - } - - public byte[] getAsByteArray() { return toByteArrayFromBitString( bits, bitCount ); } @@ -148,7 +145,7 @@ public static byte[] toByteArrayFromBitString( String bits, int bitCount ) { } int byteCount = (bitCount + 7) / 8; byte[] srcBytes; - if ( bits.length() > 0 ) { + if ( !bits.isEmpty() ) { BigInteger bigInt = new BigInteger( bits, 2 ); srcBytes = bigInt.toByteArray(); } else { diff --git a/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java b/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java index ef7c11c49f..d6faec3eb0 100644 --- a/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java +++ b/dbms/src/main/java/org/polypheny/db/ddl/DdlManagerImpl.java @@ -260,7 +260,7 @@ private void handleSource( DataSource adapter ) { } buildNamespace( Catalog.defaultNamespaceId, logical, adapter ); - adapter.createTable( null, LogicalTableWrapper.of( logical, columns ), AllocationTableWrapper.of( allocation.unwrap( AllocationTable.class ), aColumns ) ); + adapter.createTable( null, LogicalTableWrapper.of( logical, columns, List.of() ), AllocationTableWrapper.of( allocation.unwrap( AllocationTable.class ), aColumns ) ); catalog.updateSnapshot(); } @@ -732,7 +732,7 @@ public void addDataPlacement( LogicalTable table, List newColumns AllocationPlacement placement = catalog.getAllocRel( table.namespaceId ).addPlacement( table.id, table.namespaceId, dataStore.adapterId ); PartitionProperty property = catalog.getSnapshot().alloc().getPartitionProperty( table.id ).orElseThrow(); - addAllocationsForPlacement( table.namespaceId, statement, table, placement.id, adjustedColumns, property.partitionIds, dataStore ); + addAllocationsForPlacement( table.namespaceId, statement, table, placement.id, adjustedColumns, property.partitionIds, primaryKey.columnIds, dataStore ); Catalog.getInstance().updateSnapshot(); @@ -1488,7 +1488,7 @@ public void modifyPartitionPlacement( LogicalTable table, List partitionId table.id, PlacementType.AUTOMATIC, DataPlacementRole.UP_TO_DATE );*/ - addAllocationTable( table.namespaceId, statement, table, columns, placement.id, partitionId, allocationColumns, store ); + addAllocationTable( table.namespaceId, statement, table, columns, List.of(), placement.id, partitionId, allocationColumns, store ); } //storeId.createTable( statement.getPrepareContext(), LogicalTableWrapper.of( table, null ), (AllocationTableWrapper) null ); @@ -1817,7 +1817,7 @@ public void createMaterializedView( String viewName, long namespaceId, AlgRoot a for ( DataStore store : stores ) { AllocationPlacement placement = catalog.getAllocRel( namespaceId ).addPlacement( view.id, namespaceId, store.adapterId ); - addAllocationsForPlacement( namespaceId, statement, view, placement.id, List.copyOf( ids.values() ), List.of( partition.id ), store ); + addAllocationsForPlacement( namespaceId, statement, view, placement.id, List.copyOf( ids.values() ), List.of( partition.id ), List.of(), store ); } addBlankPartition( namespaceId, view.id, List.of( group.id ), List.of( partition.id ) ); @@ -2096,8 +2096,15 @@ public void createTable( long namespaceId, String name, List f ids.put( information.name, addColumn( namespaceId, information.name, information.typeInformation, information.collation, information.defaultValue, logical.id, information.position, stores, placementType ) ); } + List pkIds = new ArrayList<>(); + for ( ConstraintInformation constraint : constraints ) { - createConstraint( namespaceId, constraint.name, constraint.type, constraint.columnNames.stream().map( key -> ids.get( key ).id ).collect( Collectors.toList() ), logical.id ); + List columnIds = constraint.columnNames.stream().map( key -> ids.get( key ).id ).collect( Collectors.toList() ); + createConstraint( namespaceId, constraint.name, constraint.type, columnIds, logical.id ); + + if ( constraint.type == ConstraintType.PRIMARY ) { + pkIds = columnIds; + } } // addATable @@ -2108,7 +2115,7 @@ public void createTable( long namespaceId, String name, List f for ( DataStore store : stores ) { AllocationPlacement placement = catalog.getAllocRel( namespaceId ).addPlacement( logical.id, namespaceId, store.adapterId ); - addAllocationsForPlacement( namespaceId, statement, logical, placement.id, columns, List.of( partition.id ), store ); + addAllocationsForPlacement( namespaceId, statement, logical, placement.id, columns, pkIds, List.of( partition.id ), store ); } catalog.updateSnapshot(); @@ -2124,7 +2131,7 @@ private Pair createSinglePartition( long } - private List addAllocationsForPlacement( long namespaceId, Statement statement, LogicalTable logical, long placementId, List lColumns, List partitionIds, Adapter adapter ) { + private List addAllocationsForPlacement( long namespaceId, Statement statement, LogicalTable logical, long placementId, List lColumns, List pkIds, List partitionIds, Adapter adapter ) { List columns = new ArrayList<>(); for ( LogicalColumn column : lColumns ) { columns.add( catalog.getAllocRel( namespaceId ).addColumn( placementId, logical.id, column.id, adapter.adapterId, PlacementType.AUTOMATIC, column.position ) ); @@ -2133,7 +2140,7 @@ private List addAllocationsForPlacement( long namespaceId, Stat buildNamespace( namespaceId, logical, adapter ); List tables = new ArrayList<>(); for ( Long partitionId : partitionIds ) { - tables.add( addAllocationTable( namespaceId, statement, logical, lColumns, placementId, partitionId, columns, adapter ) ); + tables.add( addAllocationTable( namespaceId, statement, logical, lColumns, pkIds, placementId, partitionId, columns, adapter ) ); } return tables; } @@ -2156,10 +2163,10 @@ private PartitionProperty addBlankPartition( long namespaceId, long logicalEntit } - private AllocationTable addAllocationTable( long namespaceId, Statement statement, LogicalTable logical, List lColumns, long placementId, long partitionId, List aColumns, Adapter adapter ) { + private AllocationTable addAllocationTable( long namespaceId, Statement statement, LogicalTable logical, List lColumns, List pkIds, long placementId, long partitionId, List aColumns, Adapter adapter ) { AllocationTable alloc = catalog.getAllocRel( namespaceId ).addAllocation( adapter.adapterId, placementId, partitionId, logical.id ); - adapter.createTable( statement.getPrepareContext(), LogicalTableWrapper.of( logical, sortByPosition( lColumns ) ), AllocationTableWrapper.of( alloc, sortByPositionAlloc( aColumns ) ) ); + adapter.createTable( statement.getPrepareContext(), LogicalTableWrapper.of( logical, sortByPosition( lColumns ), pkIds ), AllocationTableWrapper.of( alloc, sortByPositionAlloc( aColumns ) ) ); return alloc; } @@ -2405,7 +2412,7 @@ public void createTablePartition( PartitionInformation partitionInfo, List columns = snapshot.alloc().getColumns( placement.id ); // First create new tables - AllocationTable targetTable = addAllocationTable( table.namespaceId, statement, table, logicalColumns, placement.id, partitionProperty.left.id, columns, store ); + AllocationTable targetTable = addAllocationTable( table.namespaceId, statement, table, logicalColumns, pkColumnIds, placement.id, partitionProperty.left.id, columns, store ); catalog.updateSnapshot(); dataMigrator.copyAllocationData( diff --git a/dbms/src/main/java/org/polypheny/db/partition/FrequencyMapImpl.java b/dbms/src/main/java/org/polypheny/db/partition/FrequencyMapImpl.java index 5c1c2ae7ee..a5d810adf8 100644 --- a/dbms/src/main/java/org/polypheny/db/partition/FrequencyMapImpl.java +++ b/dbms/src/main/java/org/polypheny/db/partition/FrequencyMapImpl.java @@ -346,7 +346,7 @@ private void createHotTables( LogicalTable table, List partitionsFromColdT DataPlacementRole.UP_TO_DATE ); } - store.createTable( statement.getPrepareContext(), LogicalTableWrapper.of( null, null ), AllocationTableWrapper.of( null, null ) ); + store.createTable( statement.getPrepareContext(), LogicalTableWrapper.of( null, null, null ), AllocationTableWrapper.of( null, null ) ); List logicalColumns = new ArrayList<>(); catalog.getSnapshot().alloc().getColumnPlacementsOnAdapterPerTable( store.getAdapterId(), table.id ).forEach( cp -> logicalColumns.add( catalog.getSnapshot().rel().getColumn( cp.columnId ).orElseThrow() ) ); diff --git a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java index 6719c57371..bb878f45d9 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java @@ -1145,7 +1145,7 @@ private AlgNode optimize( AlgRoot logicalRoot, Convention resultConvention ) { } - private PreparedResult implement( AlgRoot root, AlgDataType parameterRowType ) { + private PreparedResult implement( AlgRoot root, AlgDataType parameterRowType ) { if ( log.isTraceEnabled() ) { log.trace( "Physical query plan: [{}]", AlgOptUtil.dumpPlan( "-- Physical Plan", root.alg, ExplainFormat.TEXT, ExplainLevel.DIGEST_ATTRIBUTES ) ); } diff --git a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java index 6fc3ed3c0b..750efdfea3 100644 --- a/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java +++ b/plugins/avatica-interface/src/main/java/org/polypheny/db/avatica/DbmsMeta.java @@ -120,6 +120,7 @@ import org.polypheny.db.transaction.TransactionManager; import org.polypheny.db.type.PolyType; import org.polypheny.db.type.entity.PolyBigDecimal; +import org.polypheny.db.type.entity.PolyBinary; import org.polypheny.db.type.entity.PolyBoolean; import org.polypheny.db.type.entity.PolyDate; import org.polypheny.db.type.entity.PolyDouble; @@ -1292,6 +1293,8 @@ private PolyType toPolyType( Rep type ) { return PolyType.FLOAT; case STRING: return PolyType.VARCHAR; + case BYTE_STRING: + return PolyType.BINARY; case OBJECT: return PolyType.OTHER; } @@ -1342,6 +1345,8 @@ private PolyValue toPolyValue( TypedValue value ) { return PolyInteger.of( (Short) jdbc ); case BYTE: return PolyInteger.of( (byte) jdbc ); + case BYTE_STRING: + return PolyBinary.of( (byte[]) jdbc ); } throw new NotImplementedException( "dbms to poly " + value.type ); } diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/Condition.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/Condition.java index e31e6737ca..8ef4c74307 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/Condition.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/Condition.java @@ -17,30 +17,23 @@ package org.polypheny.db.adapter.file; -import java.io.File; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; import java.util.ArrayList; import java.util.Arrays; -import java.util.Calendar; -import java.util.GregorianCalendar; import java.util.List; import java.util.Set; import javax.annotation.Nullable; -import org.apache.calcite.avatica.util.DateTimeUtils; import org.apache.calcite.linq4j.tree.Expression; import org.apache.calcite.linq4j.tree.Expressions; import org.polypheny.db.adapter.DataContext; -import org.polypheny.db.adapter.file.util.FileUtil; import org.polypheny.db.algebra.constant.Kind; +import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.rex.RexCall; import org.polypheny.db.rex.RexDynamicParam; import org.polypheny.db.rex.RexIndexRef; import org.polypheny.db.rex.RexLiteral; import org.polypheny.db.rex.RexNode; import org.polypheny.db.type.PolyType; +import org.polypheny.db.type.entity.PolyValue; public class Condition { @@ -48,7 +41,7 @@ public class Condition { private final Kind operator; private Integer columnReference; private Long literalIndex; - private Object literal; + private PolyValue literal; private ArrayList operands = new ArrayList<>(); @@ -72,7 +65,7 @@ public Condition( final RexCall call ) { /** * Called by generated code, see {@link Condition#getExpression} */ - public Condition( final Kind operator, final Integer columnReference, final Long literalIndex, final Object literal, final Condition[] operands ) { + public Condition( final Kind operator, final Integer columnReference, final Long literalIndex, final PolyValue literal, final Condition[] operands ) { this.operator = operator; this.columnReference = columnReference; this.literalIndex = literalIndex; @@ -95,7 +88,7 @@ public Expression getExpression() { Expressions.constant( operator, Kind.class ), Expressions.constant( columnReference, Integer.class ), Expressions.constant( literalIndex, Long.class ), - Expressions.constant( this.literal ), + this.literal == null ? Expressions.constant( null ) : this.literal.asExpression(), Expressions.newArrayInit( Condition.class, operandsExpressions ) ); } @@ -107,7 +100,7 @@ private void assignRexNode( final RexNode rexNode ) { } else if ( rexNode instanceof RexDynamicParam ) { this.literalIndex = ((RexDynamicParam) rexNode).getIndex(); } else if ( rexNode instanceof RexLiteral ) { - this.literal = FileUtil.toObject( ((RexLiteral) rexNode).value ); + this.literal = ((RexLiteral) rexNode).value; } } @@ -141,7 +134,7 @@ public Object getPKLookup( final Set pkColumnReferences, final PolyType return null; } } - if ( pkColumnReferences.size() == 0 ) { + if ( pkColumnReferences.isEmpty() ) { return lookups; } else { return null; @@ -154,14 +147,14 @@ public Object getPKLookup( final Set pkColumnReferences, final PolyType /** * Get the value of the condition parameter, either from the literal or literalIndex */ - Object getParamValue( final DataContext dataContext, final PolyType polyType ) { - Object out; + PolyValue getParamValue( final DataContext dataContext, final PolyType polyType ) { + PolyValue out; if ( this.literalIndex != null ) { out = dataContext.getParameterValue( literalIndex ); } else { out = this.literal; } - if ( out instanceof Calendar ) { + /*if ( out instanceof Calendar ) { switch ( polyType ) { case TIME: case TIMESTAMP: @@ -170,7 +163,7 @@ Object getParamValue( final DataContext dataContext, final PolyType polyType ) { Calendar cal = ((Calendar) out); return LocalDateTime.ofInstant( cal.toInstant(), cal.getTimeZone().toZoneId() ).toLocalDate().toEpochDay(); } - } + }*/ return out; } @@ -216,7 +209,7 @@ private static boolean like( final String str, String expr ) { } - public boolean matches( final Object[] columnValues, final PolyType[] columnTypes, final DataContext dataContext ) { + public boolean matches( final PolyValue[] columnValues, final PolyType[] columnTypes, final DataContext dataContext ) { if ( columnReference == null ) { // || literalIndex == null ) { switch ( operator ) { case AND: @@ -234,14 +227,14 @@ public boolean matches( final Object[] columnValues, final PolyType[] columnType } return false; default: - throw new RuntimeException( operator + " not supported in condition without columnReference" ); + throw new GenericRuntimeException( operator + " not supported in condition without columnReference" ); } } // don't allow comparison of files and return false if Objects are not comparable - if ( columnValues[columnReference] != null && (!(columnValues[columnReference] instanceof Comparable) || (columnValues[columnReference] instanceof File)) ) { + /*if ( columnValues[columnReference] == null ) { return false; - } - Comparable columnValue = (Comparable) columnValues[columnReference];//don't do the projectionMapping here + }*/ + PolyValue columnValue = columnValues[columnReference];//don't do the projectionMapping here PolyType polyType = columnTypes[columnReference]; switch ( operator ) { case IS_NULL: @@ -253,19 +246,19 @@ public boolean matches( final Object[] columnValues, final PolyType[] columnType //if there is no null check and the column value is null, any check on the column value would return false return false; } - Object parameterValue = getParamValue( dataContext, polyType ); + PolyValue parameterValue = getParamValue( dataContext, polyType ); if ( parameterValue == null ) { //WHERE x = null is always false, see https://stackoverflow.com/questions/9581745/sql-is-null-and-null return false; } - if ( columnValue instanceof Number && parameterValue instanceof Number ) { - columnValue = ((Number) columnValue).doubleValue(); - parameterValue = ((Number) parameterValue).doubleValue(); - } + /*if ( columnValue.isNumber() && parameterValue.isNumber() ) { + columnValue = columnValue;//.doubleValue(); + parameterValue = parameterValue;//).doubleValue(); + }*/ int comparison; - if ( parameterValue instanceof Calendar ) { + /*if ( parameterValue instanceof Calendar ) { //could be improved with precision.. switch ( polyType ) { case DATE: @@ -282,7 +275,7 @@ public boolean matches( final Object[] columnValues, final PolyType[] columnType comparison = ldt.compareTo( ((GregorianCalendar) parameterValue).toZonedDateTime().toLocalDateTime() ); break; default: - comparison = columnValue.compareTo( parameterValue ); + comparison = ((Comparable) columnValue).compareTo( parameterValue ); } } else if ( FileHelper.isSqlDateOrTimeOrTS( parameterValue ) ) { switch ( polyType ) { @@ -292,11 +285,12 @@ public boolean matches( final Object[] columnValues, final PolyType[] columnType break; case TIMESTAMP: default: - comparison = columnValue.compareTo( FileHelper.sqlToLong( parameterValue ) ); + comparison = ((Comparable) columnValue).compareTo( FileHelper.sqlToLong( parameterValue ) ); } } else { - comparison = columnValue.compareTo( parameterValue ); - } + comparison = ((Comparable) columnValue).compareTo( parameterValue ); + }*/ + comparison = columnValue.compareTo( parameterValue ); switch ( operator ) { case AND: @@ -328,7 +322,7 @@ public boolean matches( final Object[] columnValues, final PolyType[] columnType case LIKE: return like( columnValue.toString(), parameterValue.toString() ); default: - throw new RuntimeException( operator + " comparison not supported by file adapter." ); + throw new GenericRuntimeException( operator + " comparison not supported by file adapter." ); } } diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileAlg.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileAlg.java index 13b75e6061..5778cebcfb 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileAlg.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileAlg.java @@ -22,6 +22,7 @@ import lombok.Getter; import lombok.Setter; import org.polypheny.db.algebra.AlgNode; +import org.polypheny.db.algebra.type.AlgDataTypeField; public interface FileAlg extends AlgNode { @@ -99,7 +100,8 @@ else if ( operation == Operation.UPDATE ) { int i = 0; List mapping = new ArrayList<>(); for ( Value update : updates ) { - int index = new ArrayList<>( getFileTable().getColumnIdNames().values() ).indexOf( columnNames.get( i ) ); + AlgDataTypeField field = getFileTable().getRowType().getField( columnNames.get( i ), false, false ); + int index = field.getIndex(); update.setColumnReference( index ); mapping.add( index ); i++; diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileEnumerator.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileEnumerator.java index 5a83908b2a..af0c702489 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileEnumerator.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileEnumerator.java @@ -17,7 +17,6 @@ package org.polypheny.db.adapter.file; -import com.google.gson.Gson; import java.io.File; import java.io.FileFilter; import java.io.IOException; @@ -38,6 +37,7 @@ import org.polypheny.db.adapter.DataContext; import org.polypheny.db.adapter.file.FileAlg.FileImplementor.Operation; import org.polypheny.db.adapter.file.FilePlugin.FileStore; +import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.transaction.Transaction.MultimediaFlavor; import org.polypheny.db.type.PolyType; import org.polypheny.db.type.PolyTypeFamily; @@ -47,7 +47,6 @@ import org.polypheny.db.type.entity.category.PolyBlob; import org.polypheny.db.util.DateString; import org.polypheny.db.util.FileInputHandle; -import org.polypheny.db.util.Pair; import org.polypheny.db.util.TimeString; import org.polypheny.db.util.TimestampString; @@ -67,7 +66,6 @@ public class FileEnumerator implements Enumerator { final Condition condition; final Integer[] projectionMapping; final PolyType[] columnTypes; - final Gson gson; final Map updates = new HashMap<>(); final Integer[] pkMapping; final File hardlinkFolder; @@ -100,7 +98,7 @@ public FileEnumerator( final Value[] updates ) { if ( dataContext.getParameterValues().size() > 1 && (operation == Operation.UPDATE || operation == Operation.DELETE) ) { - throw new RuntimeException( "The file store does not support batch update or delete statements!" ); + throw new GenericRuntimeException( "The file store does not support batch update or delete statements!" ); } this.operation = operation; @@ -129,7 +127,6 @@ public FileEnumerator( } this.pkMapping = pkMapping; - this.gson = new Gson(); Long[] columnsToIterate = columnIds; // If there is a projection and no filter, it is sufficient to just load the data of the projected columns. // If a filter is given, the whole table has to be loaded (because of the column references) @@ -147,7 +144,6 @@ public FileEnumerator( this.columnTypes = columnTypes; } // We want to read data where an insert has been prepared and skip data where a deletion has been prepared. - @SuppressWarnings("UnstableApiUsage") String xidHash = FileStore.SHA.hashString( dataContext.getStatement().getTransaction().getXid().toString(), FileStore.CHARSET ).toString(); FileFilter fileFilter = file -> !file.isHidden() && !file.getName().startsWith( "~$" ) && (!file.getName().startsWith( "_" ) || file.getName().startsWith( "_ins_" + xidHash )); for ( Long colId : columnsToIterate ) { @@ -167,7 +163,7 @@ public FileEnumerator( this.hardlinkFolder = new File( rootPath, "hardlinks/" + xidHash ); if ( !hardlinkFolder.exists() ) { if ( !hardlinkFolder.mkdirs() ) { - throw new RuntimeException( "Could not create hardlink directory " + hardlinkFolder.getAbsolutePath() ); + throw new GenericRuntimeException( "Could not create hardlink directory " + hardlinkFolder.getAbsolutePath() ); } } } @@ -247,7 +243,7 @@ else if ( fileListPosition < 0 ) { } return false; } - if ( !condition.matches( (Object[]) curr, columnTypes, dataContext ) ) { + if ( !condition.matches( curr, columnTypes, dataContext ) ) { fileListPosition++; continue; } @@ -296,7 +292,7 @@ else if ( fileListPosition < 0 ) { Set updatedColumns = new HashSet<>(); for ( int c = 0; c < columnFolders.size(); c++ ) { if ( updates.containsKey( c ) ) { - updateObj[c] = updates.get( c ).getValue( dataContext, 0 ); + updateObj[c] = updates.get( c ).getValue( dataContext, 0 ).toJson(); updatedColumns.add( c ); } else { //needed for the hash @@ -313,9 +309,6 @@ else if ( fileListPosition < 0 ) { // write new file if ( updateObj[j] != null ) { File insertFile = new File( colFolder, getNewFileName( Operation.INSERT, String.valueOf( newHash ) ) ); - /*if( newFile.exists() ) { - throw new RuntimeException("This update would lead to a primary key conflict, " + newFile.getAbsolutePath()); - }*/ //if column has not been updated: just copy the old file to the new one with the PK in the new fileName if ( !updatedColumns.contains( j ) && source.exists() ) { @@ -353,11 +346,11 @@ else if ( fileListPosition < 0 ) { fileListPosition++; //continue; } else { - throw new RuntimeException( operation + " operation is not supported in FileEnumerator" ); + throw new GenericRuntimeException( operation + " operation is not supported in FileEnumerator" ); } } } catch ( IOException | RuntimeException e ) { - throw new RuntimeException( e ); + throw new GenericRuntimeException( e ); } } @@ -417,8 +410,8 @@ private PolyValue[] fileToRow( final File currentFile ) throws IOException { } - private PolyValue[] project( final Object o1, PolyType[] columnTypes ) { - PolyValue[] o = Pair.zip( ((Object[]) o1), columnTypes ).stream().map( p -> PolyTypeUtil.stringToObject( (String) p.left, p.right ) ).toArray( PolyValue[]::new ); + private PolyValue[] project( final PolyValue[] o1, PolyType[] columnTypes ) { + PolyValue[] o = o1;//Pair.zip( o1, columnTypes ).stream().map( p -> PolyTypeUtil.stringToObject( (String) p.left, p.right ) ).toArray( PolyValue[]::new ); assert (projectionMapping != null); PolyValue[] out = new PolyValue[projectionMapping.length]; for ( int i = 0; i < projectionMapping.length; i++ ) { @@ -446,13 +439,13 @@ public void close() { int hashRow( final Object row ) { Object[] toHash = new Object[pkMapping.length]; for ( int i = 0; i < pkMapping.length; i++ ) { - toHash[i] = ((Object[]) row)[pkMapping[i]].toString(); + Object obj = ((Object[]) row)[pkMapping[i]]; + toHash[i] = obj instanceof PolyValue ? ((PolyValue) obj).toJson() : obj.toString(); } return Arrays.hashCode( toHash ); } - @SuppressWarnings("UnstableApiUsage") String getNewFileName( final Operation operation, final String hashCode ) { String operationAbbreviation;//must be of length 3! switch ( operation ) { @@ -463,16 +456,16 @@ String getNewFileName( final Operation operation, final String hashCode ) { operationAbbreviation = "del"; break; default: - throw new RuntimeException( "Did not expect operation " + operation ); + throw new GenericRuntimeException( "Did not expect operation " + operation ); } return "_"// underline at the beginning of files that are not yet committed + operationAbbreviation + "_" //XID - + FileStore.SHA.hashString( dataContext.getStatement().getTransaction().getXid().toString(), FileStore.CHARSET ).toString() + + FileStore.SHA.hashString( dataContext.getStatement().getTransaction().getXid().toString(), FileStore.CHARSET ) + "_" //PK hash - + FileStore.SHA.hashString( hashCode, FileStore.CHARSET ).toString(); + + FileStore.SHA.hashString( hashCode, FileStore.CHARSET ); } } diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileModifier.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileModifier.java index df1258dc93..48b4f71cf6 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileModifier.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileModifier.java @@ -28,6 +28,7 @@ import org.polypheny.db.adapter.DataContext; import org.polypheny.db.adapter.file.FileAlg.FileImplementor.Operation; import org.polypheny.db.adapter.file.FilePlugin.FileStore; +import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.type.PolyType; import org.polypheny.db.type.entity.PolyLong; import org.polypheny.db.util.DateString; @@ -100,7 +101,7 @@ public boolean moveNext() { return true; } } catch ( IOException | RuntimeException e ) { - throw new RuntimeException( e ); + throw new GenericRuntimeException( e ); } } diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FilePlugin.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FilePlugin.java index 8f4a1b0e2d..151d3dbf00 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FilePlugin.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FilePlugin.java @@ -209,7 +209,7 @@ public List createTable( Context context, LogicalTableWrapper lo } } - FileTranslatableEntity physical = currentNamespace.createFileTable( table ); + FileTranslatableEntity physical = currentNamespace.createFileTable( table, logical.pkIds ); storeCatalog.replacePhysical( physical ); return List.of( physical ); diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileStoreSchema.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileStoreSchema.java index da1cd0c4e0..e364429262 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileStoreSchema.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/FileStoreSchema.java @@ -70,13 +70,11 @@ public Long getAdapterId() { } - public FileTranslatableEntity createFileTable( PhysicalTable table ) { - List pkIds; - pkIds = new ArrayList<>();// todo dl + public FileTranslatableEntity createFileTable( PhysicalTable table, List primary ) { return new FileTranslatableEntity( this, table, - pkIds ); + primary ); } diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/Value.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/Value.java index cdbdf7c609..c6a62b69c3 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/Value.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/Value.java @@ -17,7 +17,6 @@ package org.polypheny.db.adapter.file; -import com.google.gson.Gson; import java.util.ArrayList; import java.util.List; import lombok.Getter; @@ -50,7 +49,6 @@ public class Value { private Integer columnReference; private PolyValue literal; private PolyValue literalIndex; - private static final Gson gson = new Gson(); /** @@ -88,15 +86,6 @@ public PolyValue getValue( final DataContext context, final int i ) { Expression getExpression() { if ( literal != null ) { - Expression literalExpression; - /*if ( literal ) { - // this is a fix, else linq4j will submit an integer that is too long - literalExpression = Expressions.constant( literal, Long.class ); - } else if ( literal instanceof BigDecimal ) { - literalExpression = Expressions.constant( literal.toString() ); - } else { - literalExpression = Expressions.constant( literal ); - }*/ return Expressions.new_( Value.class, Expressions.constant( columnReference ), literal.asExpression(), Expressions.constant( false ) ); } else { return Expressions.new_( Value.class, Expressions.constant( columnReference ), literalIndex.asExpression(), Expressions.constant( true ) ); diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileTableModify.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileTableModify.java index 9d5d16dc5c..7dc9c5f5cf 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileTableModify.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/algebra/FileTableModify.java @@ -26,6 +26,7 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.core.relational.RelModify; import org.polypheny.db.algebra.metadata.AlgMetadataQuery; +import org.polypheny.db.algebra.type.AlgDataTypeField; import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.plan.AlgOptCluster; import org.polypheny.db.plan.AlgOptCost; @@ -88,9 +89,13 @@ public void implement( final FileImplementor implementor ) { int i = 0; for ( RexNode src : getSourceExpressions() ) { if ( src instanceof RexLiteral ) { - values.add( new Value( implementor.getFileTable().getColumnNamesIds().get( getUpdateColumns().get( i ) ).intValue(), ((RexLiteral) src).value, false ) ); + String logicalName = getUpdateColumns().get( i ); + AlgDataTypeField field = entity.getRowType().getField( logicalName, false, false ); + values.add( new Value( Math.toIntExact( field.getId() ), ((RexLiteral) src).value, false ) ); } else if ( src instanceof RexDynamicParam ) { - values.add( new Value( implementor.getFileTable().getColumnNamesIds().get( getUpdateColumns().get( i ) ).intValue(), PolyLong.of( ((RexDynamicParam) src).getIndex() ), true ) ); + String logicalName = getUpdateColumns().get( i ); + AlgDataTypeField field = entity.getRowType().getField( logicalName, false, false ); + values.add( new Value( Math.toIntExact( field.getId() ), PolyLong.of( ((RexDynamicParam) src).getIndex() ), true ) ); } else if ( src instanceof RexCall && src.getType().getPolyType() == PolyType.ARRAY ) { values.add( Value.fromArrayRexCall( (RexCall) src ) ); } else { diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/source/QfsEnumerator.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/source/QfsEnumerator.java index 9cab3d26e5..434917a05b 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/source/QfsEnumerator.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/source/QfsEnumerator.java @@ -30,6 +30,9 @@ import org.polypheny.db.catalog.exceptions.GenericRuntimeException; import org.polypheny.db.transaction.Transaction.MultimediaFlavor; import org.polypheny.db.type.PolyType; +import org.polypheny.db.type.PolyTypeUtil; +import org.polypheny.db.type.entity.PolyValue; +import org.polypheny.db.util.Pair; public class QfsEnumerator implements Enumerator { @@ -91,7 +94,7 @@ public boolean moveNext() { return false; } Path path = iterator.next(); - Object[] row = getRow( path.toFile() ); + PolyValue[] row = Pair.zip( getRow( path.toFile() ), columnTypes ).stream().map( p -> PolyTypeUtil.stringToObject( p.left.toString(), p.right ) ).toArray( PolyValue[]::new ); if ( condition != null && !condition.matches( row, columnTypes, dataContext ) ) { return moveNext(); } diff --git a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/util/FileUtil.java b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/util/FileUtil.java index 2c685c820a..7963c9fa98 100644 --- a/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/util/FileUtil.java +++ b/plugins/file-adapter/src/main/java/org/polypheny/db/adapter/file/util/FileUtil.java @@ -22,7 +22,7 @@ public class FileUtil { public static Object toObject( PolyValue value ) { - return value.asString().value; + return value == null ? null : value.toJson(); } @@ -46,7 +46,7 @@ public static Object fromValue( PolyValue value ) { return value.asNumber().BigDecimalValue(); case BINARY: case VARBINARY: - return value.asBinary().value.toBase64String(); + return value.asBinary().value.getBytes(); case DOUBLE: return value.asNumber().DoubleValue(); case BOOLEAN: diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlBinaryStringLiteral.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlBinaryStringLiteral.java index 891cb1bf39..559445ea0d 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlBinaryStringLiteral.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlBinaryStringLiteral.java @@ -45,7 +45,7 @@ public SqlBinaryStringLiteral clone( ParserPos pos ) { @Override public void unparse( SqlWriter writer, int leftPrec, int rightPrec ) { assert value.isBinary(); - writer.literal( "X'" + value.asBinary().value.toBase64String() + "'" ); + writer.literal( "X'" + value.asBinary().value.toString() + "'" ); } diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlLiteral.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlLiteral.java index f0541f23ef..a2c6c77224 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlLiteral.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/language/SqlLiteral.java @@ -137,20 +137,19 @@ * * */ +@Getter public class SqlLiteral extends SqlNode implements Literal { /** * The type with which this literal was declared. This type is very approximate: the literal may have a different type once validated. For example, all numeric literals have a type name of * {@link PolyType#DECIMAL}, but on validation may become {@link PolyType#INTEGER}. */ - @Getter private final PolyType typeName; /** * The value of this literal. The type of the value must be appropriate for the typeName, as defined by the {@link #valueMatchesType} method. */ - @Getter - public final PolyValue value; //todo dl make PolyValue + public final PolyValue value; /** @@ -668,7 +667,7 @@ public static void unparsePoly( PolyType typeName, PolyValue value, SqlWriter wr writer.keyword( "NULL" ); break; case CHAR: - //case DECIMAL: + //case DECIMAL: case DOUBLE: case BINARY: // should be handled in subtype diff --git a/plugins/sql-language/src/main/java/org/polypheny/db/sql/sql2alg/SqlNodeToRexConverterImpl.java b/plugins/sql-language/src/main/java/org/polypheny/db/sql/sql2alg/SqlNodeToRexConverterImpl.java index 5f23abb9a8..09e3504976 100644 --- a/plugins/sql-language/src/main/java/org/polypheny/db/sql/sql2alg/SqlNodeToRexConverterImpl.java +++ b/plugins/sql-language/src/main/java/org/polypheny/db/sql/sql2alg/SqlNodeToRexConverterImpl.java @@ -17,9 +17,7 @@ package org.polypheny.db.sql.sql2alg; -import com.google.common.base.Preconditions; import java.math.BigDecimal; -import org.apache.calcite.avatica.util.ByteString; import org.polypheny.db.algebra.type.AlgDataType; import org.polypheny.db.algebra.type.AlgDataTypeFactory; import org.polypheny.db.rex.RexBuilder; @@ -105,14 +103,7 @@ public RexNode convertLiteral( SqlRexContext cx, SqlLiteral literal ) { case BOOLEAN: return rexBuilder.makeLiteral( literal.value.asBoolean().value ); case BINARY: - bitString = literal.getValueAs( BitString.class ); - Preconditions.checkArgument( - (bitString.getBitCount() % 8) == 0, - "incomplete octet" ); - - // An even number of hexits (e.g. X'ABCD') makes whole number of bytes. - ByteString byteString = new ByteString( bitString.getAsByteArray() ); - return rexBuilder.makeBinaryLiteral( byteString ); + return rexBuilder.makeBinaryLiteral( literal.value.asBinary().value ); case SYMBOL: return rexBuilder.makeFlag( literal.getValueAs( Enum.class ) ); case TIMESTAMP: