Fix tests

This commit is contained in:
kssenii 2022-12-22 12:15:34 +01:00
parent d3db1dd6a7
commit a58b8b8e6c
5 changed files with 25 additions and 18 deletions

View File

@ -335,6 +335,7 @@ DatabasePtr DatabaseFactory::getImpl(const ASTCreateQuery & create, const String
configuration.host = named_collection->get<String>("host");
configuration.port = static_cast<UInt16>(named_collection->get<UInt64>("port"));
configuration.addresses = {std::make_pair(configuration.host, configuration.port)};
configuration.username = named_collection->get<String>("user");
configuration.password = named_collection->get<String>("password");
configuration.database = named_collection->get<String>("database");
@ -409,6 +410,7 @@ DatabasePtr DatabaseFactory::getImpl(const ASTCreateQuery & create, const String
configuration.host = named_collection->get<String>("host");
configuration.port = static_cast<UInt16>(named_collection->get<UInt64>("port"));
configuration.addresses = {std::make_pair(configuration.host, configuration.port)};
configuration.username = named_collection->get<String>("user");
configuration.password = named_collection->get<String>("password");
configuration.database = named_collection->get<String>("database");

View File

@ -8,6 +8,11 @@
namespace DB
{
namespace ErrorCodes
{
extern const int BAD_ARGUMENTS;
}
namespace
{
NamedCollectionPtr tryGetNamedCollectionFromASTs(ASTs asts)
@ -62,11 +67,11 @@ NamedCollectionPtr tryGetNamedCollectionWithOverrides(ASTs asts)
auto collection_copy = collection->duplicate();
for (const auto & ast : asts)
for (auto it = std::next(asts.begin()); it != asts.end(); ++it)
{
auto value_override = getKeyValueFromAST(ast);
if (!value_override)
continue;
auto value_override = getKeyValueFromAST(*it);
if (!value_override && !(*it)->as<ASTFunction>())
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Expected key-value argument or function");
const auto & [key, value] = *value_override;
collection_copy->setOrUpdate<String>(key, toString(value));

View File

@ -12,7 +12,6 @@ namespace ErrorCodes
extern const int BAD_ARGUMENTS;
}
namespace DB
{

View File

@ -282,6 +282,7 @@ def test_predefined_connection_configuration(started_cluster):
result = node1.query(
"select create_table_query from system.tables where database ='postgres_database'"
)
print(f"kssenii: {result}")
assert result.strip().endswith(
"ENGINE = PostgreSQL(postgres1, table = \\'test_table\\')"
)
@ -372,6 +373,19 @@ def test_postgresql_fetch_tables(started_cluster):
cursor.execute("DROP SCHEMA IF EXISTS test_schema CASCADE")
def test_datetime(started_cluster):
cursor = started_cluster.postgres_conn.cursor()
cursor.execute("drop table if exists test")
cursor.execute("create table test (u timestamp)")
node1.query("drop database if exists pg")
node1.query("create database pg engine = PostgreSQL(postgres1)")
assert "DateTime64(6)" in node1.query("show create table pg.test")
node1.query("detach table pg.test")
node1.query("attach table pg.test")
assert "DateTime64(6)" in node1.query("show create table pg.test")
if __name__ == "__main__":
cluster.start()
input("Cluster created, press any key to destroy...")

View File

@ -693,19 +693,6 @@ def test_auto_close_connection(started_cluster):
assert count == 2
def test_datetime(started_cluster):
cursor = started_cluster.postgres_conn.cursor()
cursor.execute("drop table if exists test")
cursor.execute("create table test (u timestamp)")
node1.query("drop database if exists pg")
node1.query("create database pg engine = PostgreSQL(postgres1)")
assert "DateTime64(6)" in node1.query("show create table pg.test")
node1.query("detach table pg.test")
node1.query("attach table pg.test")
assert "DateTime64(6)" in node1.query("show create table pg.test")
if __name__ == "__main__":
cluster.start()
input("Cluster created, press any key to destroy...")