fluent/fluent-plugin-sql

timestamp is inserted as NULL

dobesv opened this issue · 3 comments

Using this config:

  <match **>
    @id yugabyte
    @type sql
    @log_level info

    adapter postgresql
    host "#{ENV['YBHOST']}"
    port "#{ENV['YBPORT']}"
    username "#{ENV['YBUSER']}"
    password "#{ENV['YBPASSWORD']}"
    database "#{ENV['YBDATABASE']}"

    <table>
      table events
      column_mapping 'timestamp,assignmentId,event,formativeId,category,label,name,sectionId,type,urlPattern,route,userId,studentId,value,selectedTab,questionNumber,viewPortHeight,viewPortWidth,pilotUser,partnerUser,premiumUser,student,teacher,utm_campaign,utm_content,utm_medium,utm_source,browserVersion,operatingSystemVersion,browser,operatingSystem,googleClientId,anonymousId,experimentId,method'
    </table>
  </match>

It always tries to insert the timestamp as NULL. Is timestamp the wrong field name?

MrJoy commented

I discovered this same issue. After digging through the code, it seems that feature never got implemented. I wound up patching the plugin to address this.

After reading through the code, I figured out the problem. You have to explicitly tell it to inject the timestamp. This should probably be added to the documentation.

e.g.

  <match **>
    @id yugabyte
    @type sql
    @log_level info

    adapter postgresql
    host "#{ENV['YBHOST']}"
    port "#{ENV['YBPORT']}"
    username "#{ENV['YBUSER']}"
    password "#{ENV['YBPASSWORD']}"
    database "#{ENV['YBDATABASE']}"

    <inject>
      time_key timestamp
      time_type string
      time_format %FT%T%.%N:z
      utc true
    </inject>

    <table>
      table events
      column_mapping 'timestamp,assignmentId,event,formativeId,category,label,name,sectionId,type,urlPattern,route,userId,studentId,value,selectedTab,questionNumber,viewPortHeight,viewPortWidth,pilotUser,partnerUser,premiumUser,student,teacher,utm_campaign,utm_content,utm_medium,utm_source,browserVersion,operatingSystemVersion,browser,operatingSystem,googleClientId,anonymousId,experimentId,method'
    </table>
  </match>

I've suggested a docs update in #93.