Skip to content

Commit

Permalink
Merge f82131e into 3f95672
Browse files Browse the repository at this point in the history
  • Loading branch information
yakud committed Jun 20, 2019
2 parents 3f95672 + f82131e commit 2f780ad
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ http://user:password@host:8123/clicks?read_timeout=10&write_timeout=20
* Date
* DateTime
* Enum
* LowCardinality(T)
* [Array(T) (one-dimensional)](https://clickhouse.yandex/reference_en.html#Array(T))
* [Nested(Name1 Type1, Name2 Type2, ...)](https://clickhouse.yandex/docs/en/data_types/nested_data_structures/nested/)

Expand Down
21 changes: 21 additions & 0 deletions dataparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ func (p *arrayParser) Parse(s io.RuneScanner) (driver.Value, error) {
return slice.Interface(), nil
}

type lowCardinalityParser struct {
arg DataParser
}

func (p *lowCardinalityParser) Type() reflect.Type {
return p.arg.Type()
}

func (p *lowCardinalityParser) Parse(s io.RuneScanner) (driver.Value, error) {
return p.arg.Parse(s)
}

func newDateTimeParser(format, locname string, unquote bool) (DataParser, error) {
loc, err := time.LoadLocation(locname)
if err != nil {
Expand Down Expand Up @@ -431,6 +443,15 @@ func newDataParser(t *TypeDesc, unquote bool) (DataParser, error) {
subParsers[i] = subParser
}
return &tupleParser{subParsers}, nil
case "LowCardinality":
if len(t.Args) != 1 {
return nil, fmt.Errorf("element type not specified for LowCardinality")
}
subParser, err := newDataParser(t.Args[0], unquote)
if err != nil {
return nil, fmt.Errorf("failed to create parser for LowCardinality elements: %v", err)
}
return &lowCardinalityParser{subParser}, nil
default:
return nil, fmt.Errorf("type %s is not supported", t.Name)
}
Expand Down
24 changes: 24 additions & 0 deletions dataparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,30 @@ func TestParseData(t *testing.T) {
inputdata: "(1,2",
failParseData: true,
},
{
name: "low cardinality string",
inputtype: "LowCardinality(String)",
inputdata: "hello",
output: "hello",
},
{
name: "low cardinality string with escaping",
inputtype: "LowCardinality(String)",
inputdata: `hello \'world`,
output: "hello 'world",
},
{
name: "low cardinality string with incorrect escaping",
inputtype: "LowCardinality(String)",
inputdata: `hello world\`,
failParseData: true,
},
{
name: "low cardinality UInt64",
inputtype: "LowCardinality(UInt64)",
inputdata: "123",
output: uint64(123),
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 2f780ad

Please sign in to comment.