Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-weber committed May 13, 2024
1 parent 88f04fe commit 6ad6196
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private static void populateDeclarationsMap() {
.opName( "AGGREGATE" ).opAlias( "AGG" ).numInputs( 1 ).opTags( logTags )
.param( Parameter.builder().name( "group" ).type( ParamType.FIELD ).multiValued( 1 ).defaultValue( ListArg.EMPTY ).build() ) // select count(*) has no group
.param( Parameter.builder().name( "groups" ).type( ParamType.FIELD ).multiValued( 2 ).defaultValue( ListArg.NESTED_EMPTY ).build() )
.param( Parameter.builder().name( "aggregates" ).type( ParamType.AGGREGATE ).multiValued( 1 ).defaultValue( ListArg.EMPTY ).build() )
.param( Parameter.builder().name( "aggregates" ).alias( "aggs" ).type( ParamType.AGGREGATE ).multiValued( 1 ).defaultValue( ListArg.EMPTY ).build() )
.build() );
declarations.put( LogicalRelMinus.class, PolyAlgDeclaration.builder()
.creator( LogicalRelMinus::create ).model( DataModel.RELATIONAL )
Expand Down Expand Up @@ -230,7 +230,7 @@ private static void populateDeclarationsMap() {
.creator( LogicalDocumentAggregate::create ).model( DataModel.DOCUMENT )
.opName( "DOC_AGGREGATE" ).opAlias( "DOC_AGG" ).numInputs( 1 ).opTags( logTags )
.param( Parameter.builder().name( "group" ).type( ParamType.REX ).defaultValue( RexArg.NULL ).build() )
.param( Parameter.builder().name( "aggs" ).multiValued( 1 ).type( ParamType.LAX_AGGREGATE ).defaultValue( ListArg.EMPTY ).build() )
.param( Parameter.builder().name( "aggregates" ).alias( "aggs" ).multiValued( 1 ).type( ParamType.LAX_AGGREGATE ).defaultValue( ListArg.EMPTY ).build() )
.build() );
declarations.put( LogicalDocumentModify.class, PolyAlgDeclaration.builder()
.creator( LogicalDocumentModify::create ).model( DataModel.DOCUMENT )
Expand Down Expand Up @@ -285,7 +285,7 @@ private static void populateDeclarationsMap() {
.creator( LogicalLpgAggregate::create ).model( DataModel.GRAPH )
.opName( "LPG_AGGREGATE" ).opAlias( "LPG_AGG" ).numInputs( 1 ).opTags( logTags )
.param( Parameter.builder().name( "groups" ).multiValued( 1 ).type( ParamType.REX ).defaultValue( ListArg.EMPTY ).build() )
.param( Parameter.builder().name( "aggs" ).multiValued( 1 ).type( ParamType.LAX_AGGREGATE ).defaultValue( ListArg.EMPTY ).build() )
.param( Parameter.builder().name( "aggregates" ).alias( "aggs" ).multiValued( 1 ).type( ParamType.LAX_AGGREGATE ).defaultValue( ListArg.EMPTY ).build() )
.build() );
declarations.put( LogicalLpgModify.class, PolyAlgDeclaration.builder()
.creator( LogicalLpgModify::create ).model( DataModel.GRAPH )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,17 @@ private PolyAlgArgs buildArgs( PolyAlgDeclaration decl, List<PolyAlgNamedArgumen
continue;
} else {
p = decl.getPos( i ); // TODO: handle invalid arguments
if (p == null) {
throw new GenericRuntimeException( "Too many positional arguments were given for " + decl.opName );
}
}
} else {
noMorePosArgs = true;

p = decl.getParam( name );
if (p == null) {
throw new GenericRuntimeException( "Unexpected keyword argument '" + name + "' for " + decl.opName );
}
}

if ( usedParams.contains( p ) ) {
Expand Down Expand Up @@ -251,7 +257,7 @@ private PolyAlgArg convertExpression( Parameter p, PolyAlgExpression exp, String
}
case AGGREGATE -> new AggArg( convertAggCall( exp, alias, ctx ) );
case LAX_AGGREGATE -> new LaxAggArg( convertLaxAggCall( exp, alias, ctx ) );
case ENTITY -> new EntityArg( convertEntity( exp, ctx.dataModel ), snapshot, ctx.dataModel );
case ENTITY -> new EntityArg( convertEntity( exp ), snapshot, ctx.dataModel );
case JOIN_TYPE_ENUM -> new EnumArg<>( exp.toEnum( JoinAlgType.class ), pType );
case SEMI_JOIN_TYPE_ENUM -> new EnumArg<>( exp.toEnum( SemiJoinType.class ), pType );
case MODIFY_OP_ENUM -> new EnumArg<>( exp.toEnum( Modify.Operation.class ), pType );
Expand Down Expand Up @@ -355,7 +361,7 @@ private RexNode convertRexLiteral( PolyAlgLiteral literal, AlgDataType type, Con
}


private Entity convertEntity( PolyAlgExpression exp, DataModel dataModel ) {
private Entity convertEntity( PolyAlgExpression exp ) {
String[] names = exp.toIdentifier().split( "\\.", 3 );
GenericRuntimeException exception = new GenericRuntimeException( "Invalid entity name: " + String.join( ".", names ) );
String namespaceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.sql.Statement;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.polypheny.db.TestHelper;
import org.polypheny.db.TestHelper.JdbcConnection;
Expand Down Expand Up @@ -131,7 +130,7 @@ public void projectPolyAlgTest() throws NodeParseException {
@Test
public void aggregatePolyAlgTest() throws NodeParseException {
String polyAlg = """
AGG[group=name, aggs=COUNT(DISTINCT foo) AS EXPR$1](
AGGREGATE[group=name, aggregates=COUNT(DISTINCT foo) AS EXPR$1](
PROJECT[foo, name](
SCAN[public.polyalg_test]))
""";
Expand All @@ -141,6 +140,32 @@ public void aggregatePolyAlgTest() throws NodeParseException {
}


@Test
public void opAliasPolyAlgTest() throws NodeParseException {
String polyAlg = """
P[foo, name](
SCAN[public.polyalg_test])
""";
AlgNode node = fromPolyAlg( polyAlg ).alg;
String polyAlgAfter = toPolyAlg( node );
assertEquals( polyAlg.replace( "P[", "PROJECT[" ).replaceAll( "\\s", "" ),
polyAlgAfter.replaceAll( "\\s", "" ) );
}


@Test
public void paramAliasPolyAlgTest() throws NodeParseException {
String polyAlg = """
SORT[fetch=2](
SCAN[public.polyalg_test])
""";
AlgNode node = fromPolyAlg( polyAlg ).alg;
String polyAlgAfter = toPolyAlg( node );
assertEquals( polyAlg.replace( "fetch=", "limit=" ).replaceAll( "\\s", "" ),
polyAlgAfter.replaceAll( "\\s", "" ) );
}


@Test
public void sortPolyAlgTest() throws NodeParseException {
String polyAlg = """
Expand Down

0 comments on commit 6ad6196

Please sign in to comment.