Skip to content
Permalink
Browse files

Fix after PR feedbacks

  • Loading branch information...
hadrienk committed Jan 23, 2019
1 parent dcee340 commit f2df52c388d747d48617ddaea45a6f7b6bcfae9b
@@ -39,7 +39,7 @@
/**
* Use this class to simplify implementation of the {@link Ordering} and {@link OrderingSpecification}
*/
public final class VtlOrdering implements Ordering, OrderingSpecification {
public final class VtlOrdering implements Ordering {

public static final Comparator<Map.Entry<String, Component>> BY_ROLE = Comparator.comparing(
entry -> entry.getValue().getRole(),
@@ -79,9 +79,9 @@ public void testFloat() {

@Test
public void testString() {
VTLString aFloat = VTLObject.of("");
assertThat(aFloat).isInstanceOf(VTLString.class);
assertThat(aFloat.getVTLType()).isEqualTo(VTLString.class);
VTLString aString = VTLObject.of("");
assertThat(aString).isInstanceOf(VTLString.class);
assertThat(aString.getVTLType()).isEqualTo(VTLString.class);
}

@Test
@@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -36,11 +36,9 @@
import no.ssb.vtl.script.expressions.equality.NotEqualExpression;
import no.ssb.vtl.script.expressions.logic.AndExpression;
import no.ssb.vtl.script.expressions.logic.OrExpression;
import no.ssb.vtl.script.expressions.logic.XorExpression;

import javax.script.SimpleBindings;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@@ -56,9 +54,9 @@ public static VtlFiltering convert(AbstractEqualityExpression equalityExpression
if ((leftOperand instanceof VariableExpression && rightOperand instanceof LiteralExpression) ||
(leftOperand instanceof LiteralExpression && rightOperand instanceof VariableExpression)) {
VariableExpression variableExpression = (VariableExpression) (leftOperand instanceof VariableExpression ?
leftOperand : rightOperand);
leftOperand : rightOperand);
LiteralExpression literalExpression = (LiteralExpression) (leftOperand instanceof LiteralExpression ?
leftOperand : rightOperand);
leftOperand : rightOperand);

// Use the internal identifier with dataset prefix if it is a membership expression.
// This should be refactored at some point.
@@ -102,14 +100,13 @@ public static VtlFiltering convert(VTLExpression predicate) {
return convert((OrExpression) predicate);
} else if (predicate instanceof AndExpression) {
return convert((AndExpression) predicate);
} else if (predicate instanceof XorExpression) {
throw new UnsupportedOperationException();
} else if (predicate instanceof AbstractEqualityExpression) {
return convert((AbstractEqualityExpression) predicate);
} else if (predicate instanceof LiteralExpression) {
VTLBoolean value = (VTLBoolean) predicate.resolve(new SimpleBindings(Collections.emptyMap()));
return VtlFiltering.literal(!value.get(), FilteringSpecification.Operator.TRUE, null, value);
}
// TODO: Handle XorExpression.
return VtlFiltering.literal(false, FilteringSpecification.Operator.TRUE, null, null);
}

@@ -21,15 +21,13 @@
*/

import com.google.common.collect.ImmutableList;
import no.ssb.vtl.model.Component;
import no.ssb.vtl.model.DataPoint;
import no.ssb.vtl.model.DataStructure;
import no.ssb.vtl.model.Dataset;
import no.ssb.vtl.model.Filtering;
import no.ssb.vtl.model.FilteringSpecification;
import no.ssb.vtl.model.Ordering;
import no.ssb.vtl.model.OrderingSpecification;
import no.ssb.vtl.model.VtlOrdering;

import java.util.Collection;
import java.util.Optional;
@@ -68,10 +68,9 @@ protected DataStructure computeDataStructure() {
VtlOrdering childrenOrdering = (VtlOrdering) computeRequiredOrdering(ordering);
VtlFiltering childrenFiltering = (VtlFiltering) computeRequiredFiltering(filtering);

Stream<DataPoint> data = getChild().computeData(childrenOrdering, childrenFiltering, components);
Stream<DataPoint> original = data;
Stream<DataPoint> original = getChild().computeData(childrenOrdering, childrenFiltering, components);

data = data.map(dataPointBindings::setDataPoint)
Stream<DataPoint> data = original.map(dataPointBindings::setDataPoint)
.filter(bindings -> {
VTLObject resolved = predicate.resolve(dataPointBindings);
return resolved.get() == null ? false : VTLBoolean.of((Boolean) resolved.get()).get();
@@ -112,12 +112,8 @@ public InnerJoinOperation(Map<String, Dataset> namedDatasets, Set<Component> ide

result = StreamSupport.stream(
new InnerJoinSpliterator<>(
new JoinKeyExtractor(
first ? left.getDataStructure() : getDataStructure(),
predicate,
first ? componentMapping.column(left)::get : c -> c
),
new JoinKeyExtractor(right.getDataStructure(), predicate, componentMapping.column(right)),
new JoinKeyExtractor(first ? left.getDataStructure() : getDataStructure(), predicate),
new JoinKeyExtractor(right.getDataStructure(), predicate),
predicate,
new InnerJoinMerger(getDataStructure(), right.getDataStructure()),
result.spliterator(),
@@ -177,14 +177,14 @@ protected DataStructure computeDataStructure() {

@Override
public FilteringSpecification computeRequiredFiltering(FilteringSpecification filtering) {
// TODO: On simple assignments like x := y we could try to transform the filter.
// TODO: transform the filter on identity assignments.
return VtlFiltering.using(getChild()).transpose(filtering);
}

@Override
public OrderingSpecification computeRequiredOrdering(OrderingSpecification ordering) {
// Remove the assigned column.
// On simple identifier assignment, we could rename the ordering.
// TODO: Rename the ordering with identity assignments.
VtlOrdering.Builder builder = VtlOrdering.using(getChild());
for (String column : ordering.columns()) {
if (!identifier.equals(column)) {
@@ -23,14 +23,11 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
import no.ssb.vtl.model.Component;
import no.ssb.vtl.model.DataPoint;
import no.ssb.vtl.model.DataStructure;
import no.ssb.vtl.model.Ordering;

import java.util.ArrayList;
import java.util.Map;
import java.util.function.Function;
import java.util.function.UnaryOperator;

/**
@@ -41,26 +38,9 @@
private final DataPoint buffer;
private final int[] indices;

/**
* Create a new JoinKeyExtractor.
*
* @param childStructure original structure.
* @param order the order representing the component to extract.
* @param mapping the mapping used to translate order component to child components.
*/
public JoinKeyExtractor(
DataStructure childStructure,
Ordering ordering,
Map<Component, Component> mapping
) {
this(childStructure, ordering, mapping::get);
}


public JoinKeyExtractor(
DataStructure childStructure,
Ordering order,
Function<Component, Component> mapper
Ordering order
) {

ImmutableList<String> fromList = ImmutableList.copyOf(childStructure.keySet());
@@ -21,7 +21,6 @@
*/

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Table;
import no.ssb.vtl.model.Component;
import no.ssb.vtl.model.DataPoint;
import no.ssb.vtl.model.Dataset;
@@ -36,7 +35,6 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@@ -107,7 +105,6 @@ public OuterJoinOperation(Map<String, Dataset> namedDatasets, Set<Component> ide
Closer closer = Closer.create();
try {

Table<Component, Dataset, Component> componentMapping = getComponentMapping();
Stream<DataPoint> original = getOrSortData(
left,
adjustOrderForStructure(requiredOrder, left.getDataStructure()),
@@ -139,13 +136,8 @@ public OuterJoinOperation(Map<String, Dataset> namedDatasets, Set<Component> ide

result = StreamSupport.stream(
new OuterJoinSpliterator<>(
new JoinKeyExtractor(
first ? left.getDataStructure() : getDataStructure(),
predicate,
first ? componentMapping.column(left)::get : c -> c
),
new JoinKeyExtractor(right.getDataStructure(), predicate, componentMapping.column(right)),
predicate,
new JoinKeyExtractor(first ? left.getDataStructure() : getDataStructure(), predicate),
new JoinKeyExtractor(right.getDataStructure(), predicate), predicate,
new OuterJoinMerger(this, right),
result.spliterator(),
rightStream.spliterator()
@@ -164,8 +156,6 @@ public OuterJoinOperation(Map<String, Dataset> namedDatasets, Set<Component> ide
}
});

// TODO: Post order and post filter.
// TODO: Closer could be moved to VtlStream.
return new VtlStream(
this,
delegate,
@@ -23,7 +23,7 @@
import no.ssb.vtl.model.Dataset;

/**
* The working dataset is a special dataset used by the join getClauses.
* The working dataset is a special dataset used by the join clauses.
*/
public interface WorkingDataset extends Dataset {
}
@@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -91,8 +91,9 @@ public AbstractJoinOperation visitJoinDefinition(VTLParser.JoinDefinitionContext
case VTLParser.OUTER:
return new OuterJoinOperation(datasets, identifiers);
case VTLParser.CROSS:
//TODO: Finish CrossJoinOperation
throw new ContextualRuntimeException("Not implemented", ctx);
//return new CrossJoinOperation(datasets, identifiers);


}
return super.visitJoinDefinition(ctx);

0 comments on commit f2df52c

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