jdbc_static:收到我没有写的SQL语法错误

时间:2019-07-03 08:40:26

标签: logstash logstash-configuration logstash-jdbc

使用logstash,我试图提取一些表,在logstash mashine上对其进行本地转换,然后将结果加载到ElasticSearch。之所以采用这种解决方案,是因为源服务器MariaDB的计算能力非常有限。

  • 我分别测试了输入{},它可以正常工作,因此与mariadb的连接是可靠的。

  • 我已经针对MicrosoftSQL服务器测试了jdbc_static过滤器。因此,logstash在当前环境中具有写权限。

  • 我已经直接在MariaDB服务器上测试了SQL语法

  • 我正在运行Logstash 6.8和Java 8(Java版本“ 1.8.0_211”)

  • 我已经尝试过mariadb jdbc连接的早期版本 (mariadb-java-client-2.4.2.jar,mariadb-java-client-2.2.6-sources, mariadb-java-client-2.3.0-sources)

我的配置文件

input {
  jdbc {

    jdbc_driver_library => "C:/Logstash/logstash-6.8.0/plugin/mariadb-java-client-2.4.2.jar"
    jdbc_driver_class => "Java::org.mariadb.jdbc.Driver"

    jdbc_connection_string => "jdbc:mariadb://xx.xx.xx
    jdbc_user => "me"
    jdbc_password => "its secret"

    schedule => "* * * * *"
    statement => "SELECT unqualifiedversionid__ FROM   AuditEventFHIR WHERE myUnqualifiedId = '0000134b-fc7f-4c3a-b681-8150068d6dbb'"

  }
}
filter {
   jdbc_static {
        loaders => [ 
          {
            id => "auditevent"
            query => "SELECT  
                    myUnqualifiedId
                    ,unqualifiedversionid__
                    ,type_
                    FROM AuditEventFHIR
                    where myUnqualifiedId = '0000134b-fc7f-4c3a-b681-8150068d6dbb'
                    "
            local_table => "l_ae"
          } 
        ]

        local_db_objects => [ 

          {
            name => "l_ae"
            index_columns => ["myUnqualifiedId"]
            columns => [
              ["myUnqualifiedId", "varchar(256)"],
              ["unqualifiedversionid__", "varchar(24)"],
              ["type_", "varchar(256)"]
            ]
          }

        ]

        local_lookups => [ 
          {
            id => "rawlogfile"
            query => "
               select myUnqualifiedId from l_ae
                "  
            target => "sql_output"
          }
        ]

        jdbc_driver_library => "C:/Logstash/logstash-6.8.0/plugin/mariadb-java-client-2.4.2.jar"
        jdbc_driver_class => "Java::org.mariadb.jdbc.Driver"     
        jdbc_connection_string => "jdbc:mariadb://xx.xx.xx.xx"
        jdbc_user => "me"
        jdbc_password => "its secret"
        }
}


output {
    stdout { codec => rubydebug }
}

我遇到了这个错误以及其他几个错误,但是我怀疑修复第一个会修复其余的错误。但是关键是在我的代码中没有单词“ LIMIT 1”

[ERROR][logstash.filters.jdbc.readonlydatabase] Exception occurred when executing loader Jdbc query count {:exception=>"Java::JavaSql::SQLSyntaxErrorException: (conn=1490) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '\"T1\" LIMIT 1' at line 8", :backtrace=>["org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(org/mariadb/jdbc/internal/util/exceptions/ExceptionMapper.java:242)", "org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(org/mariadb/jdbc/internal/util/exceptions/ExceptionMapper.java:171)", "org.mariadb.jdbc.MariaDbStatement.executeExceptionEpilogue(org/mariadb/jdbc/MariaDbStatement.java:248)", "org.mariadb.jdbc.MariaDbStatement.executeInternal(org/mariadb/jdbc/MariaDbStatement.java:338)", "org.mariadb.jdbc.MariaDbStatement.executeQuery(org/mariadb/jdbc/MariaDbStatement.java:512)", "java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:498)", "org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(org/jruby/javasupport/JavaMethod.java:425)", "org.jruby.javasupport.JavaMethod.invokeDirect(org/jruby/javasupport/JavaMethod.java:292)"]}

1 个答案:

答案 0 :(得分:0)

jdbc_static装入程序进行隐藏的SQL查询select count(*) from table limit 1,以在下载表时获取校验和。此查询包含“,而mariaDB不喜欢。

除非您将“ ANSI_QUOTES”添加到sql_mode

批处理命令

SET GLOBAL sql_mode = 'ANSI_QUOTES'