LucidDB / luciddb

DEFUNCT: See README
https://github.com/LucidDB/luciddb
Apache License 2.0
52 stars 24 forks source link

[FRG-93] Some functions cause exception when column name and table name match #777

Open dynamobi-build opened 12 years ago

dynamobi-build commented 12 years ago

[reporter="stephan", created="Wed, 22 Mar 2006 12:54:15 -0500 (GMT-05:00)"] Some functions cause exception when column name and table name match.

  create schema s;
  create table s.b (b boolean, i int primary key);
  insert into s.b values (true, 1);
  select not b from s.b;
  select b or true from s.b;
  select b and true from s.b;

Results in the exception below.

You can work around either by changing the column or table name, or by giving
the table name an alias:
  select not x.b from s.b as x;
  select not b from s.b as x; -- don't even have to use the alias!

The same is true for:
  create schema s;
  create table s.x (x int, i int primary key);
  insert into s.x values (1, 1);
  select x < 2 from s.x;
  (also happens for > = >= <= + - * / pow abs mod, probably others)

These work fine:
select b is null from s.b;
select b from s.b;


java.lang.UnsupportedOperationException: class java.lang.String: need to implement
        at org.eigenbase.util.Util.needToImplement(Util.java:847)
        at
org.eigenbase.reltype.RelDataTypeFactoryImpl$TypeImpl.getSqlTypeName(RelDataTypeFactoryImpl.java:661)
        at net.sf.farrago.type.FarragoType.isAssignableFrom(FarragoType.java:135)
        at
org.eigenbase.sql.type.OperandsTypeChecking$SimpleOperandsTypeChecking.check(OperandsTypeChecking.java:158)
        at
org.eigenbase.sql.type.OperandsTypeChecking$SimpleOperandsTypeChecking.check(OperandsTypeChecking.java:180)
        at org.eigenbase.sql.SqlOperator.checkArgTypes(SqlOperator.java:406)
        at org.eigenbase.sql.SqlOperator.getType(SqlOperator.java:382)
        at org.eigenbase.sql.SqlValidator.deriveType(SqlValidator.java:770)
        at org.eigenbase.sql.SqlValidator.expandSelectItem(SqlValidator.java:228)
        at org.eigenbase.sql.SqlValidator.validateSelect(SqlValidator.java:1347)
       at org.eigenbase.sql.SqlValidator.access$600(SqlValidator.java:50)
        at
org.eigenbase.sql.SqlValidator$SelectScope.validate(SqlValidator.java:1816)
        at org.eigenbase.sql.SqlValidator.validateQuery(SqlValidator.java:370)
        at org.eigenbase.sql.SqlValidator.validateExpression(SqlValidator.java:1258)
        at org.eigenbase.sql.SqlValidator.validate(SqlValidator.java:349)
        at
net.sf.farrago.query.FarragoPreparingStmt.validate(FarragoPreparingStmt.java:182)
        at
net.sf.farrago.db.FarragoDatabase.prepareStmtImpl(FarragoDatabase.java:546)
        at net.sf.farrago.db.FarragoDatabase.prepareStmt(FarragoDatabase.java:497)
        at net.sf.farrago.db.FarragoDbSession.prepareImpl(FarragoDbSession.java:629)
        at net.sf.farrago.db.FarragoDbSession.prepare(FarragoDbSession.java:588)
       at
net.sf.farrago.db.FarragoDbStmtContext.prepare(FarragoDbStmtContext.java:135)
        at
net.sf.farrago.jdbc.engine.FarragoJdbcEngineStatement.execute(FarragoJdbcEngineStatement.java:100)
        at sqlline.SqlLine$Commands.execute(Unknown Source)
        at sqlline.SqlLine$Commands.sql(Unknown Source)
        at sqlline.SqlLine.dispatch(Unknown Source)
        at sqlline.SqlLine.begin(Unknown Source)
        at sqlline.SqlLine.mainWithInputRedirection(Unknown Source)
        at sqlline.SqlLine.main(Unknown Source)

------- Comment #1 From John Sichi 2004-10-27 19:15 [reply] -------
From the description, I'm guessing this is due to my old REVIEW comment in SqlValidator.deriveType:

// REVIEW jvs 23-Dec-2003: what if a table and column have
// the same name?

------- Comment #2 From Julian Hyde 2004-10-30 17:36 [reply] -------
Wael, can you please take this on as part of your task to validate MULTISET and LATERAL? It's the same area of code.

In order to test LATERAL and MULTISET properly, you'll need to add more corner cases, e.g. a schema, table, and column all with the same name. I've added EMP and DEPT tables to a mock schema class which is part of SqlValidatorTest -- I will check it in tomorrow probably -- and you could add the corner cases to that mock schema. Note that the validator test runs without starting farrago, and so test-driven development for the validator is very fast and convenient.

The change I'm checking in tomorrow has several improvements to the validator which should make it easier to implement LATERAL. If the LATERAL keyword is specified, or is implicit because someone has used UNNEST, then the validation inside JoinScope should follow a slightly different code path.

I'm not sure that the SqlValidator.fullyQualify method is worth keeping. It is not a useful part of the mainstream validation process; it's just used intranslating a query to Rel format. You could consider breaking it up, or making a function which resolves names in a smarter way.

------- Comment #5 From John Sichi 2005-06-09 17:50 [reply] -------
I have fixed the most glaring part of the problem (the code I originally flagged with the REVIEW comment mentioned below) in eigenchange 3681. However, I haven't addressed the other issues raised by Julian, and I have raised some other issues as comments in the code, so I'm reassigning to him for dispatch (maybe open several more specific bugs?).