theangryangel / logstash-output-jdbc

JDBC output for Logstash
MIT License
256 stars 101 forks source link

How to use sequence in phoenix #131

Closed MrVokia closed 6 years ago

MrVokia commented 6 years ago

Config:

jdbc {
    connection_test => false
    connection_test_query => "select 1"
    driver_class => "org.apache.phoenix.queryserver.client.Driver"
    connection_string => "jdbc:phoenix:thin:url=http://hostname:8765;serialization=PROTOBUF"
    statement => [
          "UPSERT INTO TEST(ID, NAME) VALUES(?, ?)",
          "NEXT VALUE FOR TEST_SEQUENCE",
          "%{name}"
    ]
}

Environment:

Logstash-output-jdbc version: 5.3.0 Logstash version: 5.1.1

Expected

UPSERT INTO TEST(ID, NAME) VALUES(NEXT VALUE FOR TEST_SEQUENCE, 'test')

Actual Behavior

UPSERT INTO TEST(ID, NAME) VALUES('NEXT VALUE FOR TEST_SEQUENCE', 'test')

Error Exception

TypeMismatchException: ERROR 203 (22005): Type mismatch. VARCHAR cannot be coerced to BIGINT

How to remove quotes in value?

theangryangel commented 6 years ago

You're telling the plugin to pass it as a string in your statement. So it's doing exactly that.

What you want is;

jdbc {
    connection_test => false
    connection_test_query => "select 1"
    driver_class => "org.apache.phoenix.queryserver.client.Driver"
    connection_string => "jdbc:phoenix:thin:url=http://hostname:8765;serialization=PROTOBUF"
    statement => [
          "UPSERT INTO TEST(ID, NAME) VALUES(NEXT VALUE FOR TEST_SEQUENCE, ?)",
          "%{name}"
    ]
}