Code Monkey home page Code Monkey logo

Comments (8)

wivwiv avatar wivwiv commented on September 27, 2024 2
image

The \\n seem to be added when the object is converted to JSON for submission. They should be converted back when executed on the backend. This appears to be a bug in the backend's JSON conversion.

from emqx.

kjellwinblad avatar kjellwinblad commented on September 27, 2024 1

I created a ticket for the double quote string issue: https://emqx.atlassian.net/browse/EMQX-11971
@zmstone

from emqx.

zhongwencool avatar zhongwencool commented on September 27, 2024

It's work as:

   rule_test {
      actions = []
      description = ""
      enable = true
      metadata {created_at = 1708919800638}
      name = ""
      sql = """~
                SELECT
                    tokens(payload, '
        	')
                FROM "x/3
        "~"""
    }

if we want to use \n as delimiter. just pass \n to http api. not \\n.
image

image

but as @wivwiv say:

<<"SELECT\n tokens(payload, '\\n\\t')\n FROM \"x/4\\n\"">>
<<"SELECT\n tokens(payload, '\n\t')\n FROM \"x/4\n\"">>

should has the same result.

from emqx.

wivwiv avatar wivwiv commented on September 27, 2024

Expected results:

SELECT
  tokens('1
2
3
4', '\n') as c
FROM 't/#'

-- output
{ "c": ["1", "2", "3", "4"] }
SELECT
  tokens('1
2
3
4', '
') as c
FROM 't/#'

-- output
{ "c": ["1", "2", "3", "4"] }

from emqx.

zmstone avatar zmstone commented on September 27, 2024

The issue seems to be the lack of escape sequence support.

which can be addressed in two ways:

  • Add a unescape function
    SELECT
        tokens(payload, unescape('\n')) as val
    
  • Add a new quote syntax like Python's b"..." quote.
    SELECT
        tokens(payload, b"\n") as val
    

from emqx.

zmstone avatar zmstone commented on September 27, 2024

for internal ref: https://emqx.atlassian.net/browse/EMQX-11847

from emqx.

kjellwinblad avatar kjellwinblad commented on September 27, 2024

@zmstone, you are right that the issue seems to be lack of escape sequence support in the strings in the SQL like language. Another interesting thing I found is that it looks like double quote strings are supported but they get evaluated to undefined! However, double quote strings seems to work fine in the FROM clause. I wonder if we could have single quote strings to mean literal strings and use double quote strings to mean strings with escape sequence support?

Anyway I think an unescape function seems like a good first step solution as it kind of solves the problem but still allows us to extend the syntax of the SQL like language if we want to.

SELECT
  '\n' as single_q,
  "\n" as double_q,
  '
  ' as newline
FROM
  "t/#"

RESULT:

{
  "double_q": "undefined",
  "newline": "\n  ",
  "single_q": "\\n"
}

from emqx.

zmstone avatar zmstone commented on September 27, 2024

Thank you for the fix @kjellwinblad

I remember there is a issue or ticket about double quotes, but I cannot find it.
Anyways, double quotes handling is a separate matter, should create a new ticket to track it.

from emqx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.