ClassCastException with similar tables

26 views
Skip to first unread message

Hannes

unread,
May 7, 2013, 3:21:47 AM5/7/13
to opti...@googlegroups.com
Hi,

looks like tables with same columns will be mixed inside the engine somehow...

The following test case shows the issue:

public class SqlTest {

    public static class MyTable {
        public String mykey = "foo";                                                                                                                 
        public Integer myvalue = 1;                                                                                                                  
    }

    public static class MyTable2 {
        public String mykey = "foo";                                                                                                                 
        public Integer myvalue = 1;                                                                                                                  
    }

    public static class MySchema {
        public MyTable[] mytable = new MyTable[] { new MyTable() };                                                                                  
        public MyTable2[] mytable2 = new MyTable2[] { new MyTable2() };                                                                              
    }


    public static void main(String[] args) throws Exception {
        Class.forName("net.hydromatic.optiq.jdbc.Driver");                                                                                           
        Connection connection = DriverManager.getConnection("jdbc:optiq:");                                                                          
        OptiqConnection optiqConnection = connection.unwrap(OptiqConnection.class);                                                                  
        ReflectiveSchema.create(optiqConnection, optiqConnection.getRootSchema(), "TEST", mySchema);                                                 

        Statement statement = optiqConnection.createStatement();                                                                                     
        ResultSet resultSet = statement.executeQuery("SELECT \"myvalue\" from TEST.\"mytable2\"");                                                   
        while(resultSet.next()) {
            System.out.println(resultSet.getInt("myvalue"));                                                                                         
        }
        resultSet.close();                                                                                                                           
        statement.close();                                                                                                                           
        connection.close();                                                                                                                          
    }
}

Both MyTable and MyTable2 have the same columns (names and types) and this will result in the following error:

Exception in thread "main" java.lang.ClassCastException: SqlTest$MyTable2 cannot be cast to SqlTest$MyTable
at Baz$1$1.current(Unknown Source)
at net.hydromatic.optiq.runtime.ObjectEnumeratorCursor$ObjectEnumeratorGetter.getObject(ObjectEnumeratorCursor.java:57)
at net.hydromatic.optiq.runtime.AbstractCursor$AccessorImpl.getObject(AbstractCursor.java:183)
at net.hydromatic.optiq.runtime.AbstractCursor$IntAccessor.getInt(AbstractCursor.java:369)
at net.hydromatic.optiq.jdbc.OptiqResultSet.getInt(OptiqResultSet.java:255)
at SqlTest.main(SqlTest.java:62)

Thanks a lot. 

best regards, -Hannes- 

Julian Hyde

unread,
May 8, 2013, 6:34:00 PM5/8/13
to opti...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "optiq-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to optiq-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Hannes

unread,
May 13, 2013, 6:39:13 AM5/13/13
to opti...@googlegroups.com
Hi, thank you very much! 

best regards, -Hannes- 
Reply all
Reply to author
Forward
0 new messages