Skip to content
Permalink
Browse files

Use variable instead of variableExpression in on clause

  • Loading branch information...
hadrienk committed Jan 31, 2019
1 parent 466385d commit a51190432d01dba6f503d110a649e4eb48d7da58
@@ -236,7 +236,8 @@ unionExpression : 'union' '(' datasetExpression (',' datasetExpression )* ')' ;

joinExpression : '[' joinDefinition ']' '{' joinBody '}';

joinDefinition : type=( INNER | OUTER | CROSS )? variable (',' variable )* ( 'on' variableExpression (',' variableExpression )* )? ;
joinDefinition : type=( INNER | OUTER | CROSS )? datasets=joinDefinitionVariables ( 'on' identifiers=joinDefinitionVariables)? ;
joinDefinitionVariables : variable (',' variable )* ;

joinBody : joinClause (',' joinClause)* ;

@@ -21,7 +21,6 @@
*/

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import no.ssb.vtl.model.Component;
import no.ssb.vtl.model.Dataset;
import no.ssb.vtl.parser.VTLParser;
@@ -65,11 +64,11 @@ public JoinDefinitionVisitor(DatasetExpressionVisitor datasetExpressionVisitor)
return builder.build();
}

private ImmutableMap<String, Component> extractIdentifierComponents(List<VTLParser.VariableExpressionContext> identifiers,
private ImmutableMap<String, Component> extractIdentifierComponents(List<VTLParser.VariableContext> identifiers,
ImmutableMap<String, Dataset> datasets) {
ImmutableMap.Builder<String, Component> builder = ImmutableMap.builder();
ComponentVisitor componentVisitor = new ComponentVisitor(new CommonIdentifierBindings(datasets));
for (VTLParser.VariableExpressionContext identifier : identifiers) {
for (VTLParser.VariableContext identifier : identifiers) {
Component identifierComponent = componentVisitor.visit(identifier);
builder.put(identifier.getText(), identifierComponent);
}
@@ -80,9 +79,11 @@ public JoinDefinitionVisitor(DatasetExpressionVisitor datasetExpressionVisitor)
public AbstractJoinOperation visitJoinDefinition(VTLParser.JoinDefinitionContext ctx) {

// Create a component bindings to be able to resolve components.
ImmutableMap<String, Dataset> datasets = extractDatasets(ctx.variable());
ImmutableMap<String, Dataset> datasets = extractDatasets(ctx.datasets.variable());

ImmutableMap<String, Component> identifiers = extractIdentifierComponents(ctx.variableExpression(), datasets);
ImmutableMap<String, Component> identifiers = ctx.identifiers == null
? ImmutableMap.of()
: extractIdentifierComponents(ctx.identifiers.variable(), datasets);

Integer joinType = Optional.ofNullable(ctx.type).map(Token::getType).orElse(VTLParser.INNER);
switch (joinType) {

0 comments on commit a511904

Please sign in to comment.
You can’t perform that action at this time.