Skip to content

Commit

Permalink
started fixing remaining core tests
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Nov 10, 2023
1 parent ec1d154 commit 923d774
Show file tree
Hide file tree
Showing 45 changed files with 307 additions and 731 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;


/**
Expand All @@ -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;
Expand All @@ -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 \".\"" );
}
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -36,6 +39,8 @@ public class VersionCollector {

final String branch;

final String hash;

public boolean inJar = false;


Expand All @@ -56,6 +61,7 @@ private VersionCollector() {
}
version = versionProperties.getProperty( VERSION );
branch = versionProperties.getProperty( BRANCH );
hash = versionProperties.getProperty( HASH );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public Values getAsValues( PolyXid xid, AlgBuilder builder, AlgDataType rowType,


@Override
Object getRaw() {
Map<?, ?> getRaw() {
return index;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public Values getAsValues( PolyXid xid, AlgBuilder builder, AlgDataType rowType,


@Override
Object getRaw() {
Map<List<PolyValue>, Set<List<PolyValue>>> getRaw() {
return index;
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/polypheny/db/adapter/index/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -227,7 +228,7 @@ void deleteAllPrimary( final Iterable<Pair<List<PolyValue>, List<PolyValue>>> va

public abstract Values getAsValues( final PolyXid xid, AlgBuilder builder, AlgDataType rowType, final List<PolyValue> key );

abstract Object getRaw();
abstract Map<?, ?> getRaw();


interface IndexFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,17 +366,17 @@ private static Ordering<List<RexLiteral>> comparator( AlgFieldCollation fieldCol
return new Ordering<>() {
@Override
public int compare( List<RexLiteral> o1, List<RexLiteral> 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 );
}
};
default:
return new Ordering<>() {
@Override
public int compare( List<RexLiteral> o1, List<RexLiteral> 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 );
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public Boolean areColumnsUnique( Values alg, AlgMetadataQuery mq, ImmutableBitSe
for ( ImmutableList<RexLiteral> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public List<Double> averageColumnSizes( Values alg, AlgMetadataQuery mq ) {
} else {
d = 0;
for ( ImmutableList<RexLiteral> 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();
}
Expand Down Expand Up @@ -409,7 +409,7 @@ public Double averageRexSize( RexNode node, List<Double> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public boolean isNull( RexNode node ) {
ImmutableList.Builder<Set<Pair<RexIndexRef, RexNode>>> usagesBuilder = ImmutableList.builder();
for ( Map.Entry<RexIndexRef, InputRefUsage<Operator, RexNode>> entry : firstUsageFinder.usageMap.entrySet() ) {
ImmutableSet.Builder<Pair<RexIndexRef, RexNode>> usageBuilder = ImmutableSet.builder();
if ( entry.getValue().usageList.size() > 0 ) {
if ( !entry.getValue().usageList.isEmpty() ) {
for ( final Pair<Operator, RexNode> pair : entry.getValue().usageList ) {
usageBuilder.add( Pair.of( entry.getKey(), pair.getValue() ) );
}
Expand Down
25 changes: 12 additions & 13 deletions core/src/main/java/org/polypheny/db/plan/VisitorDataContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -195,34 +194,34 @@ public static DataContext of( AlgDataType rowType, List<Pair<RexIndexRef, RexNod
final AlgDataType type = inputRef.getType();

if ( type.getPolyType() == null ) {
log.warn( "{} returned null PolyType", inputRef.toString() );
log.warn( "{} returned null PolyType", inputRef );
return null;
}

switch ( type.getPolyType() ) {
case INTEGER:
return Pair.of( index, rexLiteral.getValueAs( Integer.class ) );
return Pair.of( index, rexLiteral.getValue() );
case DOUBLE:
return Pair.of( index, rexLiteral.getValueAs( Double.class ) );
return Pair.of( index, rexLiteral.getValue() );
case REAL:
return Pair.of( index, rexLiteral.getValueAs( Float.class ) );
return Pair.of( index, rexLiteral.getValue() );
case BIGINT:
return Pair.of( index, rexLiteral.getValueAs( Long.class ) );
return Pair.of( index, rexLiteral.getValue() );
case SMALLINT:
return Pair.of( index, rexLiteral.getValueAs( Short.class ) );
return Pair.of( index, rexLiteral.getValue() );
case TINYINT:
return Pair.of( index, rexLiteral.getValueAs( Byte.class ) );
return Pair.of( index, rexLiteral.getValue() );
case DECIMAL:
return Pair.of( index, rexLiteral.getValueAs( BigDecimal.class ) );
return Pair.of( index, rexLiteral.getValue() );
case DATE:
case TIME:
return Pair.of( index, rexLiteral.getValueAs( Integer.class ) );
return Pair.of( index, rexLiteral.getValue() );
case TIMESTAMP:
return Pair.of( index, rexLiteral.getValueAs( Long.class ) );
return Pair.of( index, rexLiteral.getValue() );
case CHAR:
return Pair.of( index, rexLiteral.getValueAs( Character.class ) );
return Pair.of( index, rexLiteral.getValue() );
case VARCHAR:
return Pair.of( index, rexLiteral.getValueAs( String.class ) );
return Pair.of( index, rexLiteral.getValue() );
default:
// TODO: Support few more supported cases
log.warn( "{} for value of class {} is being handled in default way", type.getPolyType(), rexLiteral.getValue().getClass() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public RexNode visitCall( final RexCall call ) {
} else if ( call.operands.get( 1 ) instanceof RexIndexRef ) {
if ( ((RexIndexRef) call.operands.get( 1 )).getIndex() == partitionColumnIndex ) {
if ( call.operands.get( 0 ) instanceof RexLiteral ) {
value = ((RexLiteral) call.operands.get( 0 )).getValueForQueryParameterizer();
value = ((RexLiteral) call.operands.get( 0 )).getValue();
values.add( value );
valueIdentified = true;
} else if ( call.operands.get( 0 ) instanceof RexDynamicParam ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public Comparable<?> visitLocalRef( RexLocalRef localRef ) {

@Override
public Comparable<?> visitLiteral( RexLiteral literal ) {
return Util.first( literal.getValue4(), N );
return Util.first( literal.getValue(), N );
}


Expand Down
Loading

0 comments on commit 923d774

Please sign in to comment.