Skip to content

Commit

Permalink
Use Static.skip rather than Util.skip
Browse files Browse the repository at this point in the history
Re-order arguments of Static.skip
  • Loading branch information
julianhyde committed Jan 5, 2024
1 parent 916ede8 commit e712593
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/hydromatic/morel/compile/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import org.apache.calcite.util.Util;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.math.BigDecimal;
Expand All @@ -68,6 +67,7 @@
import static net.hydromatic.morel.ast.Ast.Direction.DESC;
import static net.hydromatic.morel.ast.CoreBuilder.core;
import static net.hydromatic.morel.util.Pair.forEach;
import static net.hydromatic.morel.util.Static.skip;
import static net.hydromatic.morel.util.Static.str;
import static net.hydromatic.morel.util.Static.toImmutableList;
import static net.hydromatic.morel.util.Static.transform;
Expand Down Expand Up @@ -332,7 +332,7 @@ && getOnlyElement(bindings).id.type.equals(elementType)) {
}
final Core.FromStep firstStep = steps.get(0);
final Supplier<Codes.RowSink> nextFactory =
createRowSinkFactory(cx, firstStep.bindings, Util.skip(steps),
createRowSinkFactory(cx, firstStep.bindings, skip(steps),
elementType);
switch (firstStep.op) {
case INNER_JOIN:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/hydromatic/morel/compile/Extents.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
import java.util.SortedMap;

import static net.hydromatic.morel.ast.CoreBuilder.core;
import static net.hydromatic.morel.util.Static.skip;
import static net.hydromatic.morel.util.Static.transformEager;

import static org.apache.calcite.util.Util.minus;
import static org.apache.calcite.util.Util.skip;

import static java.util.Objects.requireNonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import org.apache.calcite.util.Util;

import java.util.AbstractList;
import java.util.ArrayList;
Expand All @@ -40,6 +39,7 @@

import static net.hydromatic.morel.ast.CoreBuilder.core;
import static net.hydromatic.morel.util.Ord.forEachIndexed;
import static net.hydromatic.morel.util.Static.skip;

import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -199,7 +199,7 @@ private Core.Pat listToConsRecurse(DataType listDataType,
return core.consPat(listDataType, "CONS",
core.tuplePat(typeSystem,
ImmutableList.of(args.get(0),
listToConsRecurse(listDataType, Util.skip(args)))));
listToConsRecurse(listDataType, skip(args)))));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedMap;
import org.apache.calcite.util.Util;

import java.util.ArrayList;
import java.util.List;

import static net.hydromatic.morel.ast.CoreBuilder.core;
import static net.hydromatic.morel.util.Static.append;
import static net.hydromatic.morel.util.Static.skip;

import static com.google.common.collect.Iterables.getLast;

Expand Down Expand Up @@ -140,7 +140,7 @@ private Core.From toFrom(Core.Exp exp) {
.put(idPat3.name, exp.type).build());
steps.add(
core.yield_(step.bindings, core.tuple(recordType, exp)));
steps.addAll(Util.skip(from2.steps));
steps.addAll(skip(from2.steps));
return core.from(typeSystem, steps);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/net/hydromatic/morel/compile/Resolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import com.google.common.collect.ImmutableRangeSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Range;
import org.apache.calcite.util.Util;

import java.math.BigDecimal;
import java.util.ArrayDeque;
Expand All @@ -61,11 +60,13 @@

import static net.hydromatic.morel.ast.CoreBuilder.core;
import static net.hydromatic.morel.util.Pair.forEach;
import static net.hydromatic.morel.util.Static.skip;
import static net.hydromatic.morel.util.Static.transform;
import static net.hydromatic.morel.util.Static.transformEager;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.calcite.util.Util.intersects;

/** Converts AST expressions to Core expressions. */
public class Resolver {
Expand Down Expand Up @@ -261,7 +262,7 @@ private boolean references(List<PatExp> patExps) {
};
patExps.forEach(x -> x.pat.accept(v));

return Util.intersects(refSet, defSet);
return intersects(refSet, defSet);
}

private DataType toCore(Ast.DatatypeBind bind) {
Expand Down Expand Up @@ -461,7 +462,7 @@ private Core.Exp flattenLet(List<Ast.Decl> decls, Ast.Exp exp) {
final Ast.Decl decl = decls.get(0);
final List<Binding> bindings = new ArrayList<>();
final ResolvedDecl resolvedDecl = resolve(decl, bindings);
final Core.Exp e2 = withEnv(bindings).flattenLet(Util.skip(decls), exp);
final Core.Exp e2 = withEnv(bindings).flattenLet(skip(decls), exp);
return resolvedDecl.toExp(e2);
}

Expand Down Expand Up @@ -721,7 +722,7 @@ private Core.Exp toExp(List<DataType> dataTypes, Core.Exp resultExp) {
return resultExp;
} else {
return core.local(dataTypes.get(0),
toExp(Util.skip(dataTypes), resultExp));
toExp(skip(dataTypes), resultExp));
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/hydromatic/morel/compile/SuchThatShuttle.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import org.apache.calcite.util.Holder;
import org.apache.calcite.util.Util;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.ArrayList;
Expand All @@ -52,10 +51,10 @@
import static net.hydromatic.morel.util.Pair.zip;
import static net.hydromatic.morel.util.Static.append;
import static net.hydromatic.morel.util.Static.plus;
import static net.hydromatic.morel.util.Static.skip;

import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.apache.calcite.util.Util.skip;

/**
* Converts {@code suchThat} to {@code in} wherever possible.
Expand Down Expand Up @@ -114,7 +113,7 @@ Core.From visit(Core.From from) {
fromBuilder.bindings().forEach(b ->
boundPats.put(b.id, core.id(b.id)));
final Core.Exp rewritten =
rewrite0(boundPats, scan, Util.skip(steps, i));
rewrite0(boundPats, scan, skip(steps, i));
deferredScans.scan(scan.pat, rewritten, scan.condition);
} else {
deferredScans.scan(scan.pat, scan.exp);
Expand Down Expand Up @@ -155,7 +154,7 @@ Core.From visit(Core.From from) {
}

private Core.Exp rewrite0(SortedMap<Core.NamedPat, Core.Exp> boundPats,
Core.Scan scan, Iterable<? extends Core.FromStep> laterSteps) {
Core.Scan scan, List<? extends Core.FromStep> laterSteps) {
try {
final Map<Core.IdPat, Core.Exp> scans = ImmutableMap.of();
final List<Core.Exp> filters = ImmutableList.of();
Expand All @@ -173,7 +172,8 @@ private Core.Exp rewrite0(SortedMap<Core.NamedPat, Core.Exp> boundPats,
}
}

return rewrite(scan, originalPats, boundPats, scans, filters, inFilters);
return rewrite(scan, originalPats, boundPats, scans, filters,
inFilters);
} catch (RewriteFailedException e) {
// We could not rewrite.
// Try a different approach.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/hydromatic/morel/util/Static.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ public static <E> boolean shorterThan(Iterable<E> iterable, int n) {

/** Returns all but the first element of a list. */
public static <E> List<E> skip(List<E> list) {
return skip(1, list);
return skip(list, 1);
}

/** Returns all but the first {@code count} elements of a list. */
public static <E> List<E> skip(int count, List<E> list) {
public static <E> List<E> skip(List<E> list, int count) {
return list.subList(count, list.size());
}

Expand Down

0 comments on commit e712593

Please sign in to comment.