<commit_before>module Embulk
  module Input
    class Presto < InputPlugin
      class TypeConverter

        def initialize
        end

        def convert_value(value, field)
          return nil if value.nil?
          case field["type"]
          when :string
            value
          when :long
            value.to_i
          when :double
            value.to_f
          when :boolean
            if value.is_a?(TrueClass) || value.is_a?(FalseClass)
              value
            else
              downcased_val = value.downcase
              case downcased_val
              when 'true' then true
              when 'false' then false
              when '1' then true
              when '0' then false
              else nil
              end
            end
          when :timestamp
            Time.parse(value)
          when :json
            value
          else
            raise "Unsupported type #{field['type']}"
          end
        end

        def self.get_type(type)
          if type.start_with?("boolean")
            :boolean
          elsif type.start_with?("bigint")
            :long
          elsif type.start_with?("double")
            :double
          elsif type.start_with?("decimal")
            :double
          elsif type.start_with?("varchar")
            :string
          elsif type.start_with?("varbinary")
            :string
          elsif type.start_with?("json")
            :json
          elsif type.start_with?("date")
            :timestamp
          elsif type.start_with?("time")
            :timestamp
          elsif type.start_with?("time with time zone")
            :timestamp
          elsif type.start_with?("timestamp")
            :timestamp
          elsif type.start_with?("timestamp with time zone")
            :timestamp
          elsif type.start_with?("interval year to month")
            :timestamp
          elsif type.start_with?("interval day to second")
            :timestamp
          elsif type.start_with?("array")
            :json
          elsif type.start_with?("map")
            :json
          elsif type.start_with?("row")
            :json<commit_msg>fix respond integer type.<commit_after>module Embulk
  module Input
    class Presto < InputPlugin
      class TypeConverter

        def initialize
        end

        def convert_value(value, field)
          return nil if value.nil?
          case field["type"]
          when :string
            value
          when :long
            value.to_i
          when :double
            value.to_f
          when :boolean
            if value.is_a?(TrueClass) || value.is_a?(FalseClass)
              value
            else
              downcased_val = value.downcase
              case downcased_val
              when 'true' then true
              when 'false' then false
              when '1' then true
              when '0' then false
              else nil
              end
            end
          when :timestamp
            Time.parse(value)
          when :json
            value
          else
            raise "Unsupported type #{field['type']}"
          end
        end

        def self.get_type(type)
          if type.start_with?("boolean")
            :boolean
          elsif type.start_with?("bigint")
            :long
          elsif type.start_with?("integer")
            :long
          elsif type.start_with?("double")
            :double
          elsif type.start_with?("decimal")
            :double
          elsif type.start_with?("varchar")
            :string
          elsif type.start_with?("varbinary")
            :string
          elsif type.start_with?("json")
            :json
          elsif type.start_with?("date")
            :timestamp
          elsif type.start_with?("time")
            :timestamp
          elsif type.start_with?("time with time zone")
            :timestamp
          elsif type.start_with?("timestamp")
            :timestamp
          elsif type.start_with?("timestamp with time zone")
            :timestamp
          elsif type.start_with?("interval year to month")
            :timestamp
          elsif type.start_with?("interval day to second")
            :timestamp
          elsif type.start_with?("array")
            :json
          elsif type.start_with?("map")
            :json
          elsif type.start_with?("row")
            :json
{'fraction_non_alphanumeric': 0.08192219679633868, 'fraction_numerical': 0.0009153318077803204, 'mean_word_length': 1.3139227104287983, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3212823', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1122, 'n_words': 283}