Uploaded image for project: 'Apache MetaModel'
  1. Apache MetaModel
  2. METAMODEL-1137

Handle SQL server "variant" data type by casting to varchar

    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 4.5.4
    • Fix Version/s: None
    • Environment:
      Windows & Linux

      Description

      When I am trying to run the below query:

      SELECT ct."A" FROM dbo."IMAGE_TABLE1" ct
      

      using MetaModel, it's throwing an exception:

      org.apache.metamodel.MetaModelException: Could not execute query: The "variant" data type is not supported.
      

      I completely understand that the SQL Server sqlvariant data type is not currently supported by the JDBC driver. If a query is used to retrieve data from a table that contains a column of the sqlvariant data type, an exception will occur.

      But when I am casting the "sqlvariant" column to "varchar(30)" in the query then it ran successfully using jTDS ( SQL Server and Sybase JDBC driver).

      Here is the (native) query that ran successfully:

      SELECT CAST(A as varchar(30)) from IMAGE_TABLE1
      

      The same I am expecting from Apache Meta model but Apache Meta model throwing a below exception:

      org.apache.metamodel.query.parser.QueryParserException: Not capable of parsing SELECT token: CAST(A
      	at org.apache.metamodel.query.parser.SelectItemParser.parse(SelectItemParser.java:68)
      	at org.apache.metamodel.query.parser.QueryPartParser.parseItem(QueryPartParser.java:122)
      	at org.apache.metamodel.query.parser.QueryPartParser.parse(QueryPartParser.java:93)
      	at org.apache.metamodel.query.parser.QueryParser.parseSelectClause(QueryParser.java:160)
      	at org.apache.metamodel.query.parser.QueryParser.parse(QueryParser.java:95)
      	at org.apache.metamodel.AbstractDataContext.parseQuery(AbstractDataContext.java:164)
      	at org.apache.metamodel.AbstractDataContext.executeQuery(AbstractDataContext.java:188)
      	at org.apache.metamodel.DataContextFactoryTest.testSQLVarient(DataContextFactoryTest.java:69)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at junit.framework.TestCase.runTest(TestCase.java:176)
      	at junit.framework.TestCase.runBare(TestCase.java:141)
      	at junit.framework.TestResult$1.protect(TestResult.java:122)
      	at junit.framework.TestResult.runProtected(TestResult.java:142)
      	at junit.framework.TestResult.run(TestResult.java:125)
      	at junit.framework.TestCase.run(TestCase.java:129)
      	at junit.framework.TestSuite.runTest(TestSuite.java:255)
      	at junit.framework.TestSuite.run(TestSuite.java:250)
      	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
      

        Attachments

        1. image (1).png
          148 kB
          ASHISH PANCHOLI

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ashish.pancholi ASHISH PANCHOLI
              • Votes:
                2 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: