Git Product home page Git Product logo

linq4j's Introduction

Build Status

linq4j

A port of LINQ (Language-Integrated Query) to Java.

Download

$ git clone git://github.com/julianhyde/linq4j.git linq4j

Build and test

$ mvn package

Backlog

If you would like to contribute, here are some of the tasks we have planned. Please let us know if you are starting one.

  • Implement and test the methods allowing queries on Enumerables. The methods are specified in ExtendedEnumerable, DefaultEnumerable calls the implementations in Extensions. We'll do these in tranches. Each time you implement a method, add a test similar to Linq4jTest.testWhere. Try to refactor out some helper (named inner) classes, rather than creating 2 or 3 anonymous classes per method.

  • Third tranche: implement groupBy for Enumerable.

  • Fourth tranche: implement any, all, aggregate, sum, min, max, average for Enumerable.

  • Sixth tranche: implement union, intersect, except, distinct methods for Enumerable.

  • Seventh tranche: first, last, defaultIfEmpty, elementAtOrDefault, firstOrDefault, lastOrDefault for Enumerable. May need to add a class parameter so that we can generate the right default value.

  • Eighth tranche: implement orderBy, reverse for Enumerable.

  • Ninth tranche: implement methods that require EqualityComparer.

  • Last tranche: all remaining methods for Enumerable.

  • Parser support. Either modify a Java parser (e.g. OpenJDK), or write a pre-processor. Generate Java code that includes expression trees.

  • Port Enumerable and Queryable to Scala. Change classes (in particular, collections and function types) so that user code is looks like concise, native Scala. Share as much of the back-end as possible with linq4j, but don't compromise the Scala look-and-feel of the front-end. Use adapters (and sacrifice a bit of performance) if it helps.

  • Write a simple LINQ-to-SQL provider. This would generate SQL and get data from JDBC. It's a prototype, demonstrating that we can connect the dots. Plan to throw it away.

  • In the prototype LINQ-to-SQL provider, write a simple rule to recognize a select list and where clause and push them down to SQL.

  • Test Scala front-end against LINQ-to-SQL provider.

  • A better provider using a planner framework.

  • JDBC driver on top of linq4j (not necessarily on top of the Queryable/Expression object model; more likely on the query model that this translates to).

  • Use planner framework to build back-ends to non-SQL data sources (e.g. MongoDB, Hadoop, text files).

Already implemented

Methods on Enumerable:

  • select, selectMany, where, groupJoin, join;
  • count, longCount;
  • cast, ofType;
  • toMap, toLookup, skip, skipWhile, take, takeWhile.

Methods on Queryable:

  • where, whereN
  • skip, skipWhile, skipWhileN, take, takeWhile, takeWhileN.

(Except methods that involve EqualityComparer.)

More information

linq4j's People

Contributors

cwensel avatar jganoff avatar julianhyde avatar lesleh avatar pstoellberger avatar vlsi avatar wseidel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

linq4j's Issues

Assign constant expressions to 'static final' members

BlockBuilder is fairly good at detecting constants, for example (short) 10, code generating clients (for example optiq) will generate things like "Sales department".trim(). BlockBuilder should optimize such expressions, storing them in constant members (aka static final).

We already have a notion that literals (e.g. 1 and null) are constant, and which operators modify their lvalue (see ExpressionType.modifiesLvalue). I think we'd need a notion of which classes are constant (int.class, Integer.class, String.class, Timestamp.class, ImmutableMap.class, but not AtomicInteger.class, BigDecimal.class or Map.class) and of methods that always produce the same result given the same arguments ('same' according to Objects.equals), for example String.trim but not System.currentTimeMillis or Random.nextInt.

BlockBuilder should have a built-in list of immutable classes and deterministic methods, but clients of BlockBuilder should be able to add new ones to any given instance.

And of course any expression that is a constant member is also regarded as constant. (But beware cyclic initialization.)

With this knowledge, a BlockBuilder should be able to deduce bottom-up which expressions are constant and assign them to constant members.

Linq4j and Java SE 6

Hello. I've downloaded your project but stuck with build it. I am using Java SE6 and cannot build it. So, how is it possible to use this project without having to install Java 7 ?

javadoc generation fails under JDK1.8

mvn javadoc:javadoc fails under JDK1.8. Over 100 errors. Here are a few:

[ERROR] src/main/java/net/hydromatic/linq4j/ExtendedEnumerable.java:791: error: unknown tag: TSource
[ERROR] * EqualityComparer<TSource>.
[ERROR] ^
[ERROR] src/main/java/net/hydromatic/linq4j/ExtendedEnumerable.java:937: error: malformed HTML
[ERROR] * Creates a Dictionary<TKey, TValue> from an
[ERROR] ^
[ERROR] src/main/java/net/hydromatic/linq4j/ExtendedEnumerable.java:937: error: bad use of '>'
[ERROR] * Creates a Dictionary<TKey, TValue> from an
[ERROR] ^

Is linq4j on Maven?

I'd really love to play with it, but looks like it's not available on Maven. Is it?

Expressions.ifThenElse does not work

Here's the exception when trying to print such an expression

Caused by: java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
    at java.util.ArrayList.rangeCheck(ArrayList.java:604)
    at java.util.ArrayList.get(ArrayList.java:382)
    at net.hydromatic.linq4j.expressions.ConditionalStatement.accept0(ConditionalStatement.java:55)

This might be a fix:

  void accept0(ExpressionWriter writer) {
    int ifBranches = expressionList.size();
    ifBranches -= ifBranches & 1;
    for (int i = 0; i < ifBranches; i += 2) {

How to sort by more than one property of an object - linq4j

I am using linq4j. I am only sorting by one property and would like to sort by multiple property. If is is not supported in linq4j than what other method I can use. Following is my code snippet,


import java.util.Arrays;
import java.util.List; 
import net.hydromatic.linq4j.Linq4j;
import net.hydromatic.linq4j.function.*;

public class Linq4jExample {
 public static class Employee {
 public final int empno;
 public final String name;
 public final int deptno;

public Employee(int empno, String name, int deptno) {
  this.empno = empno;
  this.name = name;
  this.deptno = deptno;
}

public String toString() {
  return "Employee(empno: " + empno +",name: " + name + ", deptno:" + deptno    + ")";
 }
 }

public static final Employee[] emps = {
  new Employee(100, "Fred", 10),
  new Employee(110, "Bill", 30),
  new Employee(120,  "Bill", 10),
  new Employee(120, "Eric", 12),
  new Employee(130, "Janet", 13),
};

public static final Function1<Employee, Integer> EMP_DEPTNO_SELECTOR =
  new Function1<Employee, Integer>() {
    public Integer apply(Employee employee) {
      return employee.deptno;
    }
     };

public static void main(String[] args) {

  List<Employee> filter=Linq4j.asEnumerable(Arrays.asList(emps)) 
            .orderBy(new Function1<Employee,String>()
        { 
        public String apply(Employee arg0)
        {
            return arg0.name;
        }

    }).toList();

  }
 }

A potential use case could be sorting by department number and then by name.

Different newlines on Windows

Summary

WIndows has trouble with newlines and I'm not sure how you want to proceed.

Failure

When I run JfrSchemaFactoryTest.canRunSimpleSelectFromClassLoad on Windows, it fails on column 2 because the newlines are different:

assertThat(rs.getString(2)).isEqualTo("""
        {
          classLoader = null
          name = "java/lang/Throwable"
          package = {
            name = "java/lang"
            module = {
              name = "java.base"
              version = "17"
              location = "jrt:/java.base"
              classLoader = null
            }
            exported = true
          }
          modifiers = 33
          hidden = false
        }
        """);

Cause

JfrSchema.getConverter is using the following converter:

else if (field.getTypeName().equals("java.lang.Class")) {
    LOGGER.log(INFO, "| -> java.lang.Class");
    return event -> event.getClass(field.getName());
}

I believe when the testcase calls rs.getString(), this is calling RecordedClass.toString() which ultimately uses StructuredWriter.lineSeparator which is initialized to String.format("%n"), and this differs by platform.

Possible solutions

Should we return the java.lang.Class in this case, rather than the RecordedClass object? The Class.toString() method should produce the same result on all platforms.

Incorrectly inlines non-final variable

Linq4j BlockBuilder incorrectly inlines a variable that might be assigned more than once along a code path. For example, in

long x = 0;
final long y = System.currentTimeMillis();
if (System.nanoTime() > 0L) {
  x = y;
}

it incorrectly inlines x, to yield

if (System.nanoTime() > 0L) {
  System.currentTimeMillis();
}

The fix is to only inline variables that are marked 'final'. The java compiler will ensure that they cannot be assigned more than once (by any code path) and cannot be read before they have been initialized.

This change may break code that relies on Linq4j inlining effectively final (but not explicitly final) variables.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.