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

Clickhouse support low cardinality #29533

Merged
merged 6 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@
* <tr><td>{@link TableSchema.TypeName#BOOL}</td> <td>{@link Schema.TypeName#BOOLEAN}</td></tr>
* </table>
*
* Nullable row columns are supported through Nullable type in ClickHouse.
* Nullable row columns are supported through Nullable type in ClickHouse. Adding support for <a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is javadoc. The statement "Adding support ..." sounds like an announcement and consider moving it to CHANGES.md

For here, consider phrasing like "Low cardinality hint is supported through LowCardinality DataType in ClickHouse."

* href="https://clickhouse.com/docs/en/sql-reference/data-types/lowcardinality">LowCardinality(DataType)</a>
* in ClickHouse.
*
* <p>Nested rows should be unnested using {@link Select#flattenedSchema()}. Type casting should be
* done using {@link org.apache.beam.sdk.schemas.transforms.Cast} before {@link ClickHouseIO}.
Expand Down
62 changes: 37 additions & 25 deletions sdks/java/io/clickhouse/src/main/javacc/ColumnTypeParser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,32 @@ TOKEN :

TOKEN :
{
< ARRAY : "ARRAY" >
| < DATE : "DATE" >
| < DATETIME : "DATETIME" >
| < ENUM8 : "ENUM8" >
| < ENUM16 : "ENUM16" >
| < FIXEDSTRING : "FIXEDSTRING" >
| < FLOAT32 : "FLOAT32" >
| < FLOAT64 : "FLOAT64" >
| < STRING : "STRING" >
| < INT8 : "INT8" >
| < INT16 : "INT16" >
| < INT32 : "INT32" >
| < INT64 : "INT64" >
| < UINT8 : "UINT8" >
| < UINT16 : "UINT16" >
| < UINT32 : "UINT32" >
| < UINT64 : "UINT64" >
| < NULLABLE : "NULLABLE" >
| < LPAREN : "(" >
| < RPAREN : ")" >
| < CAST : "CAST" >
| < AS : "AS" >
| < COMMA : "," >
| < EQ : "=" >
| < BOOL : "BOOL" >
< ARRAY : "ARRAY" >
| < DATE : "DATE" >
| < DATETIME : "DATETIME" >
| < ENUM8 : "ENUM8" >
| < ENUM16 : "ENUM16" >
| < FIXEDSTRING : "FIXEDSTRING" >
| < FLOAT32 : "FLOAT32" >
| < FLOAT64 : "FLOAT64" >
| < STRING : "STRING" >
| < INT8 : "INT8" >
| < INT16 : "INT16" >
| < INT32 : "INT32" >
| < INT64 : "INT64" >
| < UINT8 : "UINT8" >
| < UINT16 : "UINT16" >
| < UINT32 : "UINT32" >
| < UINT64 : "UINT64" >
| < NULLABLE : "NULLABLE" >
| < LPAREN : "(" >
| < RPAREN : ")" >
| < CAST : "CAST" >
| < AS : "AS" >
| < COMMA : "," >
| < EQ : "=" >
| < BOOL : "BOOL" >
| < LOWCARDINALITY : "LOWCARDINALITY" >
}

public ColumnType columnType() :
Expand All @@ -111,6 +112,7 @@ public ColumnType columnType() :
| ct = enum_()
| ct = array()
| ct = nullable()
| ct = lowcardenality()
)
{
return ct;
Expand Down Expand Up @@ -278,3 +280,13 @@ private ColumnType enum_() :
}
)
}

private ColumnType lowcardenality() :
{
ColumnType ct;
}
{
(
(<LOWCARDINALITY> <LPAREN> (ct = primitive()) <RPAREN>) { return ct; }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ public void testPrimitiveTypes() throws Exception {
Schema.Field.of("f15", FieldType.STRING),
Schema.Field.of("f16", FieldType.BYTES),
Schema.Field.of("f17", FieldType.logicalType(FixedBytes.of(3))),
Schema.Field.of("f18", FieldType.BOOLEAN));
Schema.Field.of("f18", FieldType.BOOLEAN),
Schema.Field.of("f19", FieldType.STRING));
Row row1 =
Row.withSchema(schema)
.addValue(new DateTime(2030, 10, 1, 0, 0, 0, DateTimeZone.UTC))
Expand All @@ -182,6 +183,7 @@ public void testPrimitiveTypes() throws Exception {
.addValue(new byte[] {'a', 's', 'd'})
.addValue(new byte[] {'z', 'x', 'c'})
.addValue(true)
.addValue("lowcardenality")
.build();

executeSql(
Expand All @@ -204,7 +206,8 @@ public void testPrimitiveTypes() throws Exception {
+ "f15 FixedString(3),"
+ "f16 FixedString(3),"
+ "f17 FixedString(3),"
+ "f18 Bool"
+ "f18 Bool,"
+ "f19 LowCardinality(String)"
+ ") ENGINE=Log");

pipeline.apply(Create.of(row1).withRowSchema(schema)).apply(write("test_primitive_types"));
Expand Down Expand Up @@ -233,6 +236,7 @@ public void testPrimitiveTypes() throws Exception {
assertArrayEquals(new byte[] {'a', 's', 'd'}, rs.getBytes("f16"));
assertArrayEquals(new byte[] {'z', 'x', 'c'}, rs.getBytes("f17"));
assertEquals("true", rs.getString("f18"));
assertEquals("lowcardenality", rs.getString("f19"));
}
}

Expand Down
Loading