Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

how to use sql_select or sql_raw #2553

Closed
NewSun1999 opened this issue Apr 30, 2024 · 1 comment
Closed

how to use sql_select or sql_raw #2553

NewSun1999 opened this issue Apr 30, 2024 · 1 comment

Comments

@NewSun1999
Copy link

http:
  enabled: false

input:
  label: "input_once"
  generate:
    mapping: |
      root = {"table":"demo","id":uuid_v4()}
    interval: 1s
    count: 1
pipeline:
  processors:
  - branch:
      processors:
      - gen_time:
          select: month
      - mapping: |
          root = this
          root.table = "%v%v%v".format(this.table , this.year , this.month)
          root.query = "SELECT * FROM %v%v%v WHERE create_time > ? and  create_time < ?;".format(this.table , this.year , this.month)
      - log:
          level: INFO
          message: hello ${! json("query") }
      - sql_raw:
          driver: mysql
          dsn: root:123456@tcp(127.0.0.1:3306)/test
          query: ${! json("query") }
          args_mapping: '[ this.time_start, this.time_end ]'
      result_map: 'root.test = this'

output:
  stdout:
    codec: lines

error log

level=info msg="Running main config from specified file" @service=benthos path=".\\demo.yaml"
level=info msg="Launching a benthos instance, use CTRL+C to close" @service=benthos
level=info msg="hello SELECT * FROM demo202404 WHERE create_time > ? and  create_time < ?;" @service=benthos label="" path=root.pipeline.processors.0.branch.processors.2
level=error msg="Branch error: processors failed: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '${! json(\"query\") }' at line 1" @service=benthos label="" path=root.pipeline.processors.0
{"id":"a5b4252b-8275-4b77-9613-9eb45f82ac6b","month":"04","table":"demo","time_end":"2024-04-30 16:00:00","time_start":"2024-04-30 15:00:00","week":"","year":"2024"}
level=info msg="Pipeline has terminated. Shutting down the service" @service=benthos

Remark: I wrote my own plugins gen_time add other info

( ${! json("query") } ) sql_raw(query) or sql_select (table) How to use it as a parameter

@mihaitodor
Copy link
Collaborator

mihaitodor commented May 1, 2024

Hey @NewSun1999 👋 I think the issue is that you haven't set unsafe_dynamic_query: true under the sql_raw processor. See the docs here.

PS: Converting to a discussion as per #2026.

@redpanda-data redpanda-data locked and limited conversation to collaborators May 1, 2024
@mihaitodor mihaitodor converted this issue into discussion #2558 May 1, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants