Read txt files and get MySQL data #2105
Replies: 2 comments 14 replies
-
Converting to a discussion as per: #2026 |
Beta Was this translation helpful? Give feedback.
-
Does the text in
input:
file:
paths:
- ./foo.txt
codec: all-bytes
processors:
- log:
message: ${! json("foo") }
output:
stdout: {} Output:
Note the line with "INFO bar ..." which was emitted by the
Looks like that's a limitation of the underlying MySQL client library (YUCK!!!): go-sql-driver/mysql#407 (comment) and go-sql-driver/mysql#861 You can hack around it by using the input:
sql_raw:
driver: mysql
dsn: testuser:testpass@tcp(localhost:3306)/testdb?multiStatements=true
query: "SELECT FOO, BAR FROM TEST WHERE 1 = ?"
args_mapping: |
root = [
1
]
init_statement: CREATE TABLE IF NOT EXISTS TEST (FOO INT, BAR BOOLEAN); INSERT INTO TEST (FOO, BAR) VALUES (666, 0), (42, 1);
processors:
- mutation: |
root.BAR = this.BAR == 1
output:
stdout: {} Since you also asked about booleans in #2108, as you can see from this conversation, you'll need to do the conversion manually on the Benthos side, which is why I added that |
Beta Was this translation helpful? Give feedback.
-
1.Hello, when I read the txt file, I found that the read data was not in json format and could not be operated on. My yaml is:
input:
label: ""
sftp:
address: "127.0.0.1:22"
credentials:
username: "admin"
password: "123456"
private_key_file: ""
private_key_pass: ""
paths: [/home/sftp_root/shared/123.txt]
codec: all-bytes
watcher:
enabled: false
minimum_age: 1s
poll_interval: 1s
cache: ""
pipeline:
processors: []
output:
label: ""
stdout:
codec: lines
Please tell me how I should configure it so that the txt content can be turned into a json format data,thanks
2.Another question is that when I read the int value of MySQL, I found that the obtained data became string type. How can I keep the data type unchanged, which is int?
Beta Was this translation helpful? Give feedback.
All reactions