sql icon indicating copy to clipboard operation
sql copied to clipboard

WHERE boolField = 'true', doesn't autocast (changed behavior)

Open FreCap opened this issue 4 years ago • 6 comments
trafficstars

Version 1.13

In the previous version, this type of autocasting was supported

POST my_test_ndex_bool/_doc/
{
  "field1": {
    "subFieldA": true,
    "subFieldB": 2
  }
}



POST _opendistro/_sql
{
  "query": """SELECT * FROM
  my_test_ndex_bool as i 
  WHERE 
  i.field1.subFieldA ='false'
    LIMIT 50;"""
}

However in the current one it returns:

{
  "error": {
    "reason": "There was internal problem at backend",
    "details": "= function expected {[BYTE,BYTE],[SHORT,SHORT],[INTEGER,INTEGER],[LONG,LONG],[FLOAT,FLOAT],[DOUBLE,DOUBLE],[BOOLEAN,BOOLEAN],[STRING,STRING],[TIMESTAMP,TIMESTAMP],[DATE,DATE],[TIME,TIME],[DATETIME,DATETIME],[INTERVAL,INTERVAL],[STRUCT,STRUCT],[ARRAY,ARRAY]}, but get [BOOLEAN,STRING]",
    "type": "ExpressionEvaluationException"
  },
  "status": 503
}

Should we allow auto-casting instead?

FreCap avatar Feb 24 '21 11:02 FreCap

Hi FreCap,

Thanks for reporting this breaking issue.

In the new engine released on 1.13, we don't support type auto casting. The reason it works in old engine are

  1. Elasticsearch support using "true" or "false" to represent boolean value. 2.The new engine enfore the strict type check which is missing in old engine.

Do you have any suggestion for how to fix this issue? Do you want generic type auto casting or just boolean?

penghuo avatar Feb 24 '21 18:02 penghuo

@FreCap I double checked ANSI SQL-99 but didn't find implicit casting support for this: https://crate.io/docs/sql-99/en/latest/chapters/09.html#boolean-operations. Although MySQL and PostgrelSQL does support your query (Postgre even supports string 'yes', '1' as TRUE), PostgreSQL doc says "The key words TRUE and FALSE are the preferred (SQL-compliant) method for writing Boolean constants in SQL queries".

As penghuo's comments, we may need to mark this as breaking changes or evaluate if this is very common case to support. Thanks!

dai-chen avatar Feb 24 '21 19:02 dai-chen

Thanks @dai-chen and @penghuo. IMO handling it like Postgres is probably ideal for most users since it is a less strict behavior but still well recognized.

FreCap avatar Feb 24 '21 22:02 FreCap

Thanks @dai-chen and @penghuo. IMO handling it like Postgres is probably ideal for most users since it is a less strict behavior but still well recognized.

Yeah, we'll do some evaluation. Meanwhile could you provide us your use case? For example, did you use any BI tool or others that generated this kind of query? Or you just typed it in this way manually? Thanks!

dai-chen avatar Feb 24 '21 22:02 dai-chen

Yeah, we'll do some evaluation. Great.

Yes, I have integrations with BI tools (unfortunately cannot disclose further).

FreCap avatar Feb 24 '21 22:02 FreCap

Yeah, we'll do some evaluation. Great.

Yes, I have integrations with BI tools (unfortunately cannot disclose further).

Got it. That's also what I was thinking. Will evaluate this changes. Thanks!

dai-chen avatar Feb 25 '21 00:02 dai-chen