Package org.apache.calcite.linq4j
Class Extensions
- java.lang.Object
-
- org.apache.calcite.linq4j.Extensions
-
public abstract class Extensions extends java.lang.Object
Contains what, in LINQ.NET, would be extension methods.Notes on mapping from LINQ.NET to Java
We have preserved most of the API. But we've changed a few things, so that the API is more typical Java API:
- Java method names start with a lower-case letter.
- A few methods became keywords when their first letter was converted
to lower case; hence
Expressions.break_(org.apache.calcite.linq4j.tree.LabelTarget)
- We created a Java interface
Enumerable
, similar to LINQ.NET's IEnumerable. IEnumerable is built into C#, and that gives it advantages: the standard collections implement it, and you can use any IEnumerable in a foreach loop. We made the JavaEnumerable
extendIterable
, so that it can be used in for-each loops. But the standard collections still don't implement it. A few methods that take an IEnumerable in LINQ.NET take an Iterable in LINQ4J. - LINQ.NET's Dictionary interface maps to Map in Java;
hence, the LINQ.NET
ToDictionary
methods becometoMap
. - LINQ.NET's decimal type changes to BigDecimal. (A little bit unnatural, since decimal is primitive and BigDecimal is not.)
- There is no Nullable in Java. Therefore we distinguish between methods
that return, say, Long (which may be null) and long. See for example
NullableLongFunction1
andLongFunction1
, and the variants ofExtendedEnumerable.sum(org.apache.calcite.linq4j.function.BigDecimalFunction1<TSource>)
that call them. - Java erases type parameters from argument types before resolving
overloading. Therefore similar methods have the same erasure. Methods
averageDouble
,averageInteger
,groupByK
,selectN
,selectManyN
,skipWhileN
,sumBigDecimal
,sumNullableBigDecimal
,whereN
have been renamed fromaverage
,groupBy
,max
,min
,select
,selectMany
,skipWhile
andwhere
to prevent ambiguity. - .NET allows extension methods — static methods that then
become, via compiler magic, a method of any object whose type is the
same as the first parameter of the extension method. In LINQ.NET, the
IQueryable
andIEnumerable
interfaces have many such methods. In Java, those methods need to be explicitly added to the interface, and will need to be implemented by every class that implements that interface. We can help by implementing the methods as static methods, and by providing an abstract base class that implements the extension methods in the interface. HenceAbstractEnumerable
andAbstractQueryable
call methods inExtensions
. - .NET Func becomes
Function0
,Function1
,Function2
, depending on the number of arguments to the function, because Java types cannot be overloaded based on the number of type parameters. - Types map as follows:
Int32
→int
orInteger
,Int64
→long
orLong
,bool
→boolean
orBoolean
,Dictionary
→Map
,Lookup
→Map
whose value type is anIterable
, - Function types that accept primitive types in LINQ.NET have become
boxed types in LINQ4J. For example, a predicate function
Func<T, bool>
becomesFunc1<T, Boolean>
. It would be wrong to infer that the function is allowed to return null.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static Function2<java.math.BigDecimal,java.math.BigDecimal,java.math.BigDecimal>
BIG_DECIMAL_SUM
(package private) static Function2<java.lang.Comparable,java.lang.Comparable,java.lang.Comparable>
COMPARABLE_MAX
(package private) static Function2<java.lang.Comparable,java.lang.Comparable,java.lang.Comparable>
COMPARABLE_MIN
(package private) static Function2<java.lang.Double,java.lang.Double,java.lang.Double>
DOUBLE_MAX
(package private) static Function2<java.lang.Double,java.lang.Double,java.lang.Double>
DOUBLE_MIN
(package private) static Function2<java.lang.Double,java.lang.Double,java.lang.Double>
DOUBLE_SUM
(package private) static Function2<java.lang.Float,java.lang.Float,java.lang.Float>
FLOAT_MAX
(package private) static Function2<java.lang.Float,java.lang.Float,java.lang.Float>
FLOAT_MIN
(package private) static Function2<java.lang.Float,java.lang.Float,java.lang.Float>
FLOAT_SUM
(package private) static Function2<java.lang.Integer,java.lang.Integer,java.lang.Integer>
INTEGER_MAX
(package private) static Function2<java.lang.Integer,java.lang.Integer,java.lang.Integer>
INTEGER_MIN
(package private) static Function2<java.lang.Integer,java.lang.Integer,java.lang.Integer>
INTEGER_SUM
(package private) static Function2<java.lang.Long,java.lang.Long,java.lang.Long>
LONG_MAX
(package private) static Function2<java.lang.Long,java.lang.Long,java.lang.Long>
LONG_MIN
(package private) static Function2<java.lang.Long,java.lang.Long,java.lang.Long>
LONG_SUM
-
Constructor Summary
Constructors Modifier Constructor Description private
Extensions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Queryable<T>
asQueryable(DefaultEnumerable<T> source)
(package private) static <T extends java.lang.Comparable<T>>
java.util.Comparator<T>comparableComparator()
static java.lang.RuntimeException
todo()
-
-
-
Field Detail
-
BIG_DECIMAL_SUM
static final Function2<java.math.BigDecimal,java.math.BigDecimal,java.math.BigDecimal> BIG_DECIMAL_SUM
-
FLOAT_SUM
static final Function2<java.lang.Float,java.lang.Float,java.lang.Float> FLOAT_SUM
-
DOUBLE_SUM
static final Function2<java.lang.Double,java.lang.Double,java.lang.Double> DOUBLE_SUM
-
INTEGER_SUM
static final Function2<java.lang.Integer,java.lang.Integer,java.lang.Integer> INTEGER_SUM
-
LONG_SUM
static final Function2<java.lang.Long,java.lang.Long,java.lang.Long> LONG_SUM
-
COMPARABLE_MIN
static final Function2<java.lang.Comparable,java.lang.Comparable,java.lang.Comparable> COMPARABLE_MIN
-
COMPARABLE_MAX
static final Function2<java.lang.Comparable,java.lang.Comparable,java.lang.Comparable> COMPARABLE_MAX
-
FLOAT_MIN
static final Function2<java.lang.Float,java.lang.Float,java.lang.Float> FLOAT_MIN
-
FLOAT_MAX
static final Function2<java.lang.Float,java.lang.Float,java.lang.Float> FLOAT_MAX
-
DOUBLE_MIN
static final Function2<java.lang.Double,java.lang.Double,java.lang.Double> DOUBLE_MIN
-
DOUBLE_MAX
static final Function2<java.lang.Double,java.lang.Double,java.lang.Double> DOUBLE_MAX
-
INTEGER_MIN
static final Function2<java.lang.Integer,java.lang.Integer,java.lang.Integer> INTEGER_MIN
-
INTEGER_MAX
static final Function2<java.lang.Integer,java.lang.Integer,java.lang.Integer> INTEGER_MAX
-
LONG_MIN
static final Function2<java.lang.Long,java.lang.Long,java.lang.Long> LONG_MIN
-
LONG_MAX
static final Function2<java.lang.Long,java.lang.Long,java.lang.Long> LONG_MAX
-
-
Method Detail
-
todo
public static java.lang.RuntimeException todo()
-
asQueryable
public static <T> Queryable<T> asQueryable(DefaultEnumerable<T> source)
-
comparableComparator
static <T extends java.lang.Comparable<T>> java.util.Comparator<T> comparableComparator()
-
-