Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/clemensv/avrotize
Browse files Browse the repository at this point in the history
  • Loading branch information
clemensv committed Oct 16, 2024
2 parents efa3b4a + 3404e0c commit 82fddde
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 8 additions & 0 deletions avrotize/avrotodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ def convert_avro_to_sql(avro_schema_path, dbscript_file_path, db_dialect, emit_c
if isinstance(schema, list):
tables_sql = []
for schema in schema_list:
if not isinstance(schema, dict) or "type" not in schema or schema["type"] != "record":
continue
tables_sql.extend(generate_sql(
schema, db_dialect, emit_cloudevents_columns, schema_list, schema_name))
with open(dbscript_file_path, "w", encoding="utf-8") as sql_file:
sql_file.write("\n".join(tables_sql))
else:
if not isinstance(schema, dict) or "type" not in schema or schema["type"] != "record":
raise ValueError("Invalid Avro record schema")
tables_sql = generate_sql(
schema, db_dialect, emit_cloudevents_columns, schema_list, schema_name)
with open(dbscript_file_path, "w", encoding="utf-8") as sql_file:
Expand Down Expand Up @@ -662,6 +666,8 @@ def convert_avro_to_nosql(avro_schema_path, nosql_file_path, nosql_dialect, emit

if isinstance(schema, list):
for schema in schema_list:
if not isinstance(schema, dict) or "type" not in schema or schema["type"] != "record":
continue
model = generate_nosql(schema, nosql_dialect,
emit_cloudevents_columns, schema_list)
file_name = os.path.join(
Expand All @@ -672,6 +678,8 @@ def convert_avro_to_nosql(avro_schema_path, nosql_file_path, nosql_dialect, emit
else:
nosql_file.write(model)
else:
if not isinstance(schema, dict) or "type" not in schema or schema["type"] != "record":
raise ValueError("Invalid Avro record schema")
model = generate_nosql(schema, nosql_dialect,
emit_cloudevents_columns, schema_list)
file_name = os.path.join(
Expand Down
2 changes: 2 additions & 0 deletions avrotize/avrotokusto.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ def convert_avro_to_kusto_script(self, avro_schema_path, avro_record_type, emit_

type_dict = build_flat_type_dict(schema)
for record in schema:
if not isinstance(record, dict) or "type" not in record or record["type"] != "record":
continue
kusto_script.extend(self.convert_record_to_kusto(type_dict,
record, emit_cloudevents_columns, emit_cloudevents_dispatch_table))
return "\n".join(kusto_script)
Expand Down
10 changes: 6 additions & 4 deletions test/test_avrotodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,12 @@ def run_mongodb_schema_creation(self, avro_name):
self.assertTrue(collection.lower() == self.get_fullname(avro_schema).lower())
client.close()

def test_mssql_schema_creation(self):
"""Test schema creation for Microsoft SQL Server database."""
self.run_mssql_schema_creation("address")
self.run_mssql_schema_creation("northwind")
# driver issue
#def test_mssql_schema_creation(self):
# """Test schema creation for Microsoft SQL Server database."""
# self.run_mssql_schema_creation("address")
# self.run_mssql_schema_creation("northwind")


def run_mssql_schema_creation(self, avro_name):
"""Test schema creation for Microsoft SQL Server database."""
Expand Down

0 comments on commit 82fddde

Please sign in to comment.