Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance support for CAST and/or CONVERT functions for more data types #256

Open
Yury-Fridlyand opened this issue Oct 29, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request tdvt Tableau test framework

Comments

@Yury-Fridlyand
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
Functions CAST and CONVERT are not fully supported. A user should be able to convert data between the following types: integer, double, [var]char, date, datetime, time.

Describe the solution you'd like
Support them according to the standard: cast, convert.

Describe alternatives you've considered
STR function could be used to convert data into strings, but it also not supported.

Additional context
String to float CAST works:

curl -XPOST http://localhost:9200/_plugins/_sql -H 'Content-Type: application/json' -
d '{"query": "SELECT cast(\"25.5\" as float)"}'
{
  "schema": [
    {
      "name": "cast(\"25.5\" as float)",
      "type": "float"
    }
  ],
  "datarows": [
    [
      25.0
    ]
  ],
  "total": 1,
  "size": 1,
  "status": 200
}

But not in vice-versa:

curl -XPOST http://localhost:9200/_plugins/_sql -H 'Content-Type: application/json' -d '{"query": "SELECT cast(25.5 as varchar)"}'
{
  "error": {
    "reason": "There was internal problem at backend",
    "details": "class com.alibaba.druid.sql.ast.expr.SQLNumberExpr cannot be cast to class com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLNumberExpr and com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr are in unnamed module of loader java.net.FactoryURLClassLoader @1a01d7f0)",
    "type": "ClassCastException"
  },
  "status": 503
}

CONVERT:

curl -XPOST http://localhost:9200/_plugins/_sql -H 'Content-Type: application/json' -d '{"query": "SELECT convert(varchar, 25.5)"}'
{
  "error": {
    "reason": "Invalid SQL query",
    "details": "Cannot invoke \"com.alibaba.druid.sql.ast.statement.SQLTableSource.getAlias()\" because the return value of \"com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.getFrom()\" is null",
    "type": "NullPointerException"
  },
  "status": 400
}
curl -XPOST http://localhost:9200/_plugins/_sql -H 'Content-Type: application/json' -d '{"query": "SELECT convert(double, \"25.5\")"}'
{
  "error": {
    "reason": "Invalid SQL query",
    "details": "Cannot invoke \"com.alibaba.druid.sql.ast.statement.SQLTableSource.getAlias()\" because the return value of \"com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.getFrom()\" is null",
    "type": "NullPointerException"
  },
  "status": 400
}
@Yury-Fridlyand Yury-Fridlyand added the enhancement New feature or request label Oct 29, 2021
@ghost
Copy link

ghost commented Nov 19, 2021

This issue affects TDVT tests:

  • exprtests/standard\setup.cast.str.txt
  • exprtests/standard\setup.cast.int.nulls.txt

@joshuali925 joshuali925 added the tdvt Tableau test framework label Nov 24, 2021
@dai-chen
Copy link
Collaborator

The initial efforts were put on conversion from string to date/bool types:

  1. Support implicit type conversion from string to boolean #166
  2. Support implicit type conversion from string to temporal #171

More support are needed and thus use this issue to track all further requirements:

  1. [BUG] Tableau Connector Casting Bool To String Fails #571

@Yury-Fridlyand
Copy link
Collaborator Author

See also: #853

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tdvt Tableau test framework
Projects
None yet
Development

No branches or pull requests

3 participants