Skip to content

Commit 1aab3fd

Browse files
committed
Extend the unit test to test the charset and collation
1 parent 6864f84 commit 1aab3fd

1 file changed

Lines changed: 71 additions & 13 deletions

File tree

  • src/admin/python/lsst/qserv/admin

src/admin/python/lsst/qserv/admin/itest.py

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,12 @@ def run_http_ingest(
11111111
# this scenario..
11121112
database = "user_test-db"
11131113
table_json = "json-table"
1114+
table_json_utf8 = "json-table-utf8"
11141115
table_csv = "csv$table"
1116+
table_csv_utf8 = "csv$table-utf8"
11151117
timeout = 30
1118+
charset = "utf8mb4"
1119+
collation = "utf8mb4_uca1400_ai_ci"
11161120

11171121
_log.debug("Testing user database: %s", database)
11181122

@@ -1138,6 +1142,19 @@ def run_http_ingest(
11381142
_log.error("Failed to query table: %s of user database: %s, error: ", table_json, database, e)
11391143
return False
11401144

1145+
# Create the table and ingest data using the JSON option. Then query the table.
1146+
try:
1147+
_http_ingest_data_json(http_frontend_uri, user, password, database, table_json_utf8, schema, indexes, rows, charset, collation)
1148+
except Exception as e:
1149+
_log.error("Failed to ingest data into table: %s of user database: %s, error: %s", table_json_utf8, database, e)
1150+
return False
1151+
try:
1152+
_http_query_table(http_frontend_uri, user, password, database, table_json_utf8, rows)
1153+
except Exception as e:
1154+
_log.error("Failed to query table: %s of user database: %s, error: ", table_json_utf8, database, e)
1155+
return False
1156+
1157+
11411158
# Create the table and ingest data using the CSV option. Then query the table.
11421159
try:
11431160
_http_ingest_data_csv(http_frontend_uri, user, password, database, table_csv, schema, indexes, rows, timeout)
@@ -1149,10 +1166,21 @@ def run_http_ingest(
11491166
except Exception as e:
11501167
_log.error("Failed to query table: %s of user database: %s, error: ", table_csv, database, e)
11511168

1169+
# Create the table and ingest data using the CSV option. Then query the table.
1170+
try:
1171+
_http_ingest_data_csv(http_frontend_uri, user, password, database, table_csv_utf8, schema, indexes, rows, timeout, charset, collation)
1172+
except Exception as e:
1173+
_log.error("Failed to ingest data into table: %s of user database: %s, error: %s", table_csv_utf8, database, e)
1174+
return False
1175+
try:
1176+
_http_query_table(http_frontend_uri, user, password, database, table_csv_utf8, rows)
1177+
except Exception as e:
1178+
_log.error("Failed to query table: %s of user database: %s, error: ", table_csv_utf8, database, e)
1179+
11521180
# Cleanup the tables and the database in two separate steps unless the user
11531181
# requested to keep the results.
11541182
if not keep_results:
1155-
for table in [table_json, table_csv]:
1183+
for table in [table_json, table_json_utf8, table_csv, table_csv_utf8]:
11561184
try:
11571185
_http_delete_table(http_frontend_uri, user, password, database, table)
11581186
except Exception as e:
@@ -1234,6 +1262,8 @@ def _http_ingest_data_json(
12341262
schema: List[Dict[str, str]],
12351263
indexes: List[Dict[str, Sequence[Collection[str]]]],
12361264
rows: List[List[Any]],
1265+
charset: Optional[str] = None,
1266+
collation: Optional[str] = None,
12371267
) -> None:
12381268
"""Ingest data into an existing table of the user database.
12391269
@@ -1253,6 +1283,14 @@ def _http_ingest_data_json(
12531283
The schema of the table to be created.
12541284
indexes : `list` [`dict` [`str`, `list` [`list` [`str`]]]]
12551285
The indexes of the table to be created.
1286+
rows : `list` [`list` [`Any`]]
1287+
The rows of data to be ingested into the table.
1288+
charset : `str`, optional
1289+
The character set to use for the table. If not provided, the default
1290+
character set will be used.
1291+
collation : `str`, optional
1292+
The collation to use for the table. If not provided, the default
1293+
collation will be used.
12561294
"""
12571295
_log.debug("Ingesting JSON data into table: %s of user database: %s", table, database)
12581296
data = {
@@ -1262,6 +1300,11 @@ def _http_ingest_data_json(
12621300
"indexes": indexes,
12631301
"rows": rows,
12641302
}
1303+
if charset is not None:
1304+
data["charset_name"] = charset
1305+
if collation is not None:
1306+
data["collation_name"] = collation
1307+
12651308
url = str(urljoin(http_frontend_uri, f"/ingest/data?version={repl_api_version}"))
12661309
req = requests.post(url, json=data, verify=False, auth=(requests.auth.HTTPBasicAuth(user, password)))
12671310
req.raise_for_status()
@@ -1279,7 +1322,9 @@ def _http_ingest_data_csv(
12791322
schema: List[Dict[str, str]],
12801323
indexes: List[Dict[str, Sequence[Collection[str]]]],
12811324
rows: List[List[Any]],
1282-
timeout: int
1325+
timeout: int,
1326+
charset: Optional[str] = None,
1327+
collation: Optional[str] = None,
12831328
) -> None:
12841329
"""Create the table and ingest the data into the table.
12851330
@@ -1299,7 +1344,16 @@ def _http_ingest_data_csv(
12991344
The schema of the table to be created.
13001345
indexes : `list` [`dict` [`str`, `list` [`list` [`str`]]]]
13011346
The indexes of the table to be created.
1347+
rows : `list` [`list` [`Any`]]
1348+
The rows of data to be ingested into the table.
13021349
timeout : `int`
1350+
The timeout for the ingestion operation in seconds.
1351+
charset : `str`, optional
1352+
The character set to use for the table. If not provided, the default
1353+
character set will be used.
1354+
collation : `str`, optional
1355+
The collation to use for the table. If not provided, the default
1356+
collation will be used.
13031357
"""
13041358
_log.debug("Ingesting CSV data into table: %s of user database: %s", table, database)
13051359
base_dir = "/tmp"
@@ -1319,17 +1373,21 @@ def _http_ingest_data_csv(
13191373
for row in rows:
13201374
csv_writer.writerow(row)
13211375

1322-
encoder = MultipartEncoder(
1323-
fields = {
1324-
"database" : (None, database),
1325-
"table": (None, table),
1326-
"fields_terminated_by": (None, ","),
1327-
"timeout": (None, str(timeout)),
1328-
"schema": (schema_file, open(schema_file_path, "rb"), "application/json"),
1329-
"indexes": (indexes_file, open(indexes_file_path, "rb"), "application/json"),
1330-
"rows": (rows_file, open(rows_file_path, "rb"), "text/csv"),
1331-
}
1332-
)
1376+
fields = {
1377+
"database" : (None, database),
1378+
"table": (None, table),
1379+
"fields_terminated_by": (None, ","),
1380+
"timeout": (None, str(timeout)),
1381+
"schema": (schema_file, open(schema_file_path, "rb"), "application/json"),
1382+
"indexes": (indexes_file, open(indexes_file_path, "rb"), "application/json"),
1383+
"rows": (rows_file, open(rows_file_path, "rb"), "text/csv"),
1384+
}
1385+
if charset is not None:
1386+
fields["charset_name"] = (None, charset)
1387+
if collation is not None:
1388+
fields["collation_name"] = (None, collation)
1389+
1390+
encoder = MultipartEncoder(fields=fields)
13331391
url = str(urljoin(http_frontend_uri, f"/ingest/csv?version={repl_api_version}"))
13341392
req = requests.post(url, data=encoder, headers={'Content-Type': encoder.content_type}, verify=False,
13351393
auth=(requests.auth.HTTPBasicAuth(user, password)))

0 commit comments

Comments
 (0)