Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullable field-types support #6

Closed
wants to merge 1 commit into from
Closed

Nullable field-types support #6

wants to merge 1 commit into from

Conversation

workgena
Copy link

@workgena workgena commented May 29, 2017

Official documentation does not describes this feature.

Some documentation can be found at ClickHouse/doc/example_datasets/nyc_taxi.md

In this PR I skipped Enum8 and Enum16, don't sure if they can be Nullable.

fixes #5

@workgena
Copy link
Author

workgena commented May 29, 2017

I'm not 100% sure about current implementation. It may broke something.
The other possible(safe) solution may be:

        def parse_value(type, value)
          if value
            case type
              when "UInt8", "UInt16", "UInt32", "UInt64", "Int8", "Int16", "Int32", "Int64"
                parse_int_value value
              when "Float32", "Float64"
                parse_float_value value
              when "String", "Enum8", "Enum16"
                parse_string_value value
              when /FixedString\(\d+\)/
                parse_fixed_string_value value
              when "Date"
                parse_date_value value
              when "DateTime"
                parse_date_time_value value
              when /Array\(/
                parse_array_value value
              else
                raise NotImplementedError, "Cannot parse value of type #{type.inspect}"
            end
          else
            parse_null_value(type)
          end
        end

        def parse_null_value(type)
          case type
            when "Nullable(UInt8)", "Nullable(UInt16)", "Nullable(UInt32)", "Nullable(UInt64)", "Nullable(Int8)", "Nullable(Int16)", "Nullable(Int32)",  "Nullable(Int64)"
              0
            when "Nullable(Float64)", "Nullable(Float32)"
              0.0
            when "Nullable(String)"
              ''
            when /Nullable\(FixedString\(\d+\)\)/
              ''
            else
              raise NotImplementedError, "Cannot parse value of type #{type.inspect}"
          end
        end

ResultSet#parse_value accepts Nullable types

Added this types:
"Nullable(UInt8)", "Nullable(UInt16)", "Nullable(UInt32)", "Nullable(UInt64)", "Nullable(Int8)", "Nullable(Int16)", "Nullable(Int32)",  "Nullable(Int64)"
"Nullable(Float64)", "Nullable(Float32)"
"Nullable(String)"
"Nullable(DateTime)"
@workgena workgena closed this Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nullable fields
1 participant