Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion docs/src/main/sphinx/connector/clickhouse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Requirements

To connect to a ClickHouse server, you need:

* ClickHouse (version 21.3 or higher) or Altinity (version 20.8 or higher).
* ClickHouse (version 21.8 or higher) or Altinity (version 20.8 or higher).
* Network access from the Trino coordinator and workers to the ClickHouse
server. Port 8123 is the default port.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,13 +634,13 @@ public void testInsertIntoNotNullColumn()
@Override
protected String errorMessageForCreateTableAsSelectNegativeDate(String date)
{
return "Date must be between 1970-01-01 and 2106-02-07 in ClickHouse: " + date;
return "Date must be between 1970-01-01 and 2149-06-06 in ClickHouse: " + date;
}

@Override
protected String errorMessageForInsertNegativeDate(String date)
{
return "Date must be between 1970-01-01 and 2106-02-07 in ClickHouse: " + date;
return "Date must be between 1970-01-01 and 2149-06-06 in ClickHouse: " + date;
}

@Test
Expand All @@ -656,7 +656,7 @@ public void testDateYearOfEraPredicate()

protected String errorMessageForDateYearOfEraPredicate(String date)
{
return "Date must be between 1970-01-01 and 2106-02-07 in ClickHouse: " + date;
return "Date must be between 1970-01-01 and 2149-06-06 in ClickHouse: " + date;
}

@Override
Expand Down Expand Up @@ -845,6 +845,13 @@ public void testRenameTableToLongTableName()
assertFalse(getQueryRunner().tableExists(getSession(), invalidTargetTableName));
}

@Override
protected OptionalInt maxTableNameLength()
{
// The numeric value depends on file system
return OptionalInt.of(255 - ".sql.detached".length());
}

@Override
protected SqlExecutor onRemoteDatabase()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ public Object[][] clickHouseDateMinMaxValuesDataProvider()
{
return new Object[][] {
{"1970-01-01"}, // min value in ClickHouse
{"2106-02-07"}, // max value in ClickHouse
{"2149-06-06"}, // max value in ClickHouse
};
}

Expand All @@ -675,7 +675,7 @@ public Object[][] unsupportedClickHouseDateValuesDataProvider()
{
return new Object[][] {
{"1969-12-31"}, // min - 1 day
{"2106-02-08"}, // max + 1 day
{"2149-06-07"}, // max + 1 day
};
}

Expand Down Expand Up @@ -715,7 +715,7 @@ private SqlDataTypeTest timestampTest(String inputType)
protected SqlDataTypeTest unsupportedTimestampBecomeUnexpectedValueTest(String inputType)
{
return SqlDataTypeTest.create()
.addRoundTrip(inputType, "'1969-12-31 23:59:59'", createTimestampType(0), "TIMESTAMP '1970-01-01 23:59:59'"); // unsupported timestamp become 1970-01-01 23:59:59
.addRoundTrip(inputType, "'1969-12-31 23:59:59'", createTimestampType(0), "TIMESTAMP '1970-01-01 00:00:00'");
}

@Test(dataProvider = "clickHouseDateTimeMinMaxValuesDataProvider")
Expand Down Expand Up @@ -747,7 +747,7 @@ public Object[][] clickHouseDateTimeMinMaxValuesDataProvider()
{
return new Object[][] {
{"1970-01-01 00:00:00"}, // min value in ClickHouse
{"2106-02-06 06:28:15"}, // max value in ClickHouse
{"2106-02-07 06:28:15"}, // max value in ClickHouse
};
}

Expand All @@ -774,7 +774,7 @@ public Object[][] unsupportedTimestampDataProvider()
{
return new Object[][] {
{"1969-12-31 23:59:59"}, // min - 1 second
{"2106-02-06 06:28:16"}, // max + 1 second
{"2106-02-07 06:28:16"}, // max + 1 second
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import com.google.common.collect.ImmutableMap;
import io.trino.testing.QueryRunner;

import java.util.OptionalInt;

import static io.trino.plugin.clickhouse.ClickHouseQueryRunner.createClickHouseQueryRunner;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

Expand Down Expand Up @@ -45,50 +43,11 @@ public void testCommentTable()
.hasMessageContaining("Code: 62, e.displayText() = DB::Exception: Syntax error");
}

@Override
public void testCreateTableWithTableComment()
{
// Table comment is unsupported in old ClickHouse version
assertThatThrownBy(super::testCreateTableWithTableComment)
.hasMessageMatching("(?s).* Syntax error: .* COMMENT 'test comment'.*");
}

@Override
public void testCreateTableAsSelectWithTableComment()
{
// Table comment is unsupported in old ClickHouse version
assertThatThrownBy(super::testCreateTableAsSelectWithTableComment)
.hasMessageMatching("(?s).* Syntax error: .* COMMENT 'test comment'.*");
}

@Override
public void testCreateTableWithTableCommentSpecialCharacter(String comment)
{
// Table comment is unsupported in old ClickHouse version
assertThatThrownBy(() -> super.testCreateTableWithTableCommentSpecialCharacter(comment))
.hasMessageMatching("(?s).* Syntax error: .* COMMENT .*");
}

@Override
public void testCreateTableAsSelectWithTableCommentSpecialCharacter(String comment)
{
// Table comment is unsupported in old ClickHouse version
assertThatThrownBy(() -> super.testCreateTableAsSelectWithTableCommentSpecialCharacter(comment))
.hasMessageMatching("(?s).* Syntax error: .* COMMENT .*");
}

@Override
public void testCommentTableSpecialCharacter(String comment)
{
// Table comment is unsupported in old ClickHouse version
assertThatThrownBy(() -> super.testCommentTableSpecialCharacter(comment))
.hasMessageMatching("(?s).* Syntax error: .* COMMENT .*");
}

@Override
protected OptionalInt maxTableNameLength()
{
// The numeric value depends on file system
return OptionalInt.of(255 - ".sql.tmp".length());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import com.google.common.collect.ImmutableMap;
import io.trino.testing.QueryRunner;

import java.util.OptionalInt;

import static io.trino.plugin.clickhouse.ClickHouseQueryRunner.createClickHouseQueryRunner;
import static io.trino.plugin.clickhouse.TestingClickHouseServer.CLICKHOUSE_LATEST_IMAGE;

Expand All @@ -37,32 +35,4 @@ protected QueryRunner createQueryRunner()
.buildOrThrow(),
REQUIRED_TPCH_TABLES);
}

@Override
protected OptionalInt maxTableNameLength()
{
// The numeric value depends on file system
return OptionalInt.of(255 - ".sql.detached".length());
}

@Override
protected String errorMessageForCreateTableAsSelectNegativeDate(String date)
{
// Override because the DateTime range was expanded in version 21.4 and later
return "Date must be between 1970-01-01 and 2149-06-06 in ClickHouse: " + date;
}

@Override
protected String errorMessageForInsertNegativeDate(String date)
{
// Override because the DateTime range was expanded in version 21.4 and later
return "Date must be between 1970-01-01 and 2149-06-06 in ClickHouse: " + date;
}

@Override
protected String errorMessageForDateYearOfEraPredicate(String date)
{
// Override because the DateTime range was expanded in version 21.4 and later
return "Date must be between 1970-01-01 and 2149-06-06 in ClickHouse: " + date;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@
*/
package io.trino.plugin.clickhouse;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.trino.testing.QueryRunner;
import io.trino.testing.datatype.SqlDataTypeTest;
import org.testng.annotations.DataProvider;

import static io.trino.plugin.clickhouse.ClickHouseQueryRunner.createClickHouseQueryRunner;
import static io.trino.plugin.clickhouse.TestingClickHouseServer.CLICKHOUSE_LATEST_IMAGE;
import static io.trino.spi.type.TimestampType.createTimestampType;

public class TestClickHouseLatestTypeMapping
extends BaseClickHouseTypeMapping
Expand All @@ -31,65 +26,6 @@ protected QueryRunner createQueryRunner()
throws Exception
{
clickhouseServer = closeAfterClass(new TestingClickHouseServer(CLICKHOUSE_LATEST_IMAGE));
return createClickHouseQueryRunner(clickhouseServer, ImmutableMap.of(),
ImmutableMap.<String, String>builder()
.put("metadata.cache-ttl", "10m")
.put("metadata.cache-missing", "true")
.buildOrThrow(),
ImmutableList.of());
}

@DataProvider
@Override
public Object[][] clickHouseDateMinMaxValuesDataProvider()
{
// Override because the Date range was expanded in version 21.4 and later
return new Object[][] {
{"1970-01-01"}, // min value in ClickHouse
{"2149-06-06"}, // max value in ClickHouse
};
}

@DataProvider
@Override
public Object[][] unsupportedClickHouseDateValuesDataProvider()
{
// Override because the Date range was expanded in version 21.4 and later
return new Object[][] {
{"1969-12-31"}, // min - 1 day
{"2149-06-07"}, // max + 1 day
};
}

@Override
protected SqlDataTypeTest unsupportedTimestampBecomeUnexpectedValueTest(String inputType)
{
// Override because insert DateTime '1969-12-31 23:59:59' directly in ClickHouse will
// become '1970-01-01 00:00:00' in version 21.4 and later, however in versions prior
// to 21.4 the value will become '1970-01-01 23:59:59'.
return SqlDataTypeTest.create()
.addRoundTrip(inputType, "'1969-12-31 23:59:59'", createTimestampType(0), "TIMESTAMP '1970-01-01 00:00:00'");
}

@DataProvider
@Override
public Object[][] clickHouseDateTimeMinMaxValuesDataProvider()
{
// Override because the DateTime range was expanded in version 21.4 and later
return new Object[][] {
{"1970-01-01 00:00:00"}, // min value in ClickHouse
{"2106-02-07 06:28:15"}, // max value in ClickHouse
};
}

@DataProvider
@Override
public Object[][] unsupportedTimestampDataProvider()
{
// Override because the DateTime range was expanded in version 21.4 and later
return new Object[][] {
{"1969-12-31 23:59:59"}, // min - 1 second
{"2106-02-07 06:28:16"}, // max + 1 second
};
return createClickHouseQueryRunner(clickhouseServer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
package io.trino.plugin.clickhouse;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.trino.testing.QueryRunner;

import static io.trino.plugin.clickhouse.ClickHouseQueryRunner.createClickHouseQueryRunner;
Expand All @@ -27,11 +25,6 @@ protected QueryRunner createQueryRunner()
throws Exception
{
clickhouseServer = closeAfterClass(new TestingClickHouseServer());
return createClickHouseQueryRunner(clickhouseServer, ImmutableMap.of(),
ImmutableMap.<String, String>builder()
.put("metadata.cache-ttl", "10m")
.put("metadata.cache-missing", "true")
.buildOrThrow(),
ImmutableList.of());
return createClickHouseQueryRunner(clickhouseServer);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

any specific reason to remove metadata cache from type mapping tests?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Here's elapsed time comparison in my laptop. No improvement by metadata cache.

  • with cache: 1m 36s
  • without cache: 1m 33s

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class TestingClickHouseServer
{
private static final DockerImageName CLICKHOUSE_IMAGE = DockerImageName.parse("yandex/clickhouse-server");
public static final DockerImageName CLICKHOUSE_LATEST_IMAGE = CLICKHOUSE_IMAGE.withTag("21.11.10.1");
public static final DockerImageName CLICKHOUSE_DEFAULT_IMAGE = CLICKHOUSE_IMAGE.withTag("21.3.2.5"); // EOL is 30 Mar 2022
public static final DockerImageName CLICKHOUSE_DEFAULT_IMAGE = CLICKHOUSE_IMAGE.withTag("21.8.14.5"); // EOL is 31 Aug 2022

private static final String CLICKHOUSE_LATEST_DRIVER_CLASS_NAME = "com.clickhouse.jdbc.ClickHouseDriver";
// TODO: This Driver will not be available when clickhouse-jdbc is upgraded to 0.4.0 or above
Expand Down