Skip to content

Commit 4521543

Browse files
committed
bugfix for empty queries
1 parent 2f35817 commit 4521543

2 files changed

Lines changed: 38 additions & 30 deletions

File tree

materializationengine/blueprints/client/api2.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
from materializationengine.schemas import AnalysisTableSchema, AnalysisVersionSchema
7272
from materializationengine.utils import check_read_permission
7373

74-
__version__ = "5.14.0"
74+
__version__ = "5.13.5"
7575

7676

7777
authorizations = {
@@ -651,6 +651,13 @@ def combine_queries(
651651
if (prod_df is None) and (mat_df is None):
652652
abort(400, f"This query on table {user_data['table']} returned no results")
653653

654+
# if there is nothing to combine, just return the prod table to reflect
655+
# schema with no rows
656+
if (mat_df is None) and len(prod_df)==0:
657+
cut_prod_df = prod_df.drop(crud_columns, axis=1,errors="ignore")
658+
if len(created_columns) > 0:
659+
cut_prod_df = cut_prod_df.drop(created_columns, axis=1,errors="ignore")
660+
return cut_prod_df.reset_index()
654661

655662
if prod_df is not None:
656663
# if we are moving forward in time

materializationengine/blueprints/client/query.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -85,37 +85,38 @@ def fix_columns_with_query(
8585
):
8686
"""Use a query object to suggest how to convert columns imported from csv to correct types."""
8787

88-
if len(df) > 0:
89-
n_tables = len(query.column_descriptions)
88+
89+
n_tables = len(query.column_descriptions)
90+
if n_tables == 1:
91+
schema_model = query.column_descriptions[0]["type"]
92+
for colname in df.columns:
9093
if n_tables == 1:
91-
schema_model = query.column_descriptions[0]["type"]
92-
for colname in df.columns:
93-
if n_tables == 1:
94-
coltype = type(getattr(schema_model, colname).type)
95-
else:
96-
coltype = type(
97-
next(
98-
col["type"]
99-
for col in query.column_descriptions
100-
if col["name"] == colname
101-
)
102-
)
103-
if coltype is Boolean:
104-
pass
105-
# df[colname] = _fix_boolean_column(df[colname])
106-
elif coltype is DateTime:
107-
# if the first entry for this column has a decimal point,
108-
# then it is one format and we want to convert it using that format
109-
df[colname] = pd.to_datetime(
110-
df[colname], utc=True, format='ISO8601'
111-
)
112-
113-
elif coltype is Geometry and fix_wkb is True:
114-
df[colname] = fix_wkb_column(
115-
df[colname],
116-
wkb_data_start_ind=wkb_data_start_ind,
117-
n_threads=n_threads,
94+
coltype = type(getattr(schema_model, colname).type)
95+
else:
96+
coltype = type(
97+
next(
98+
col["type"]
99+
for col in query.column_descriptions
100+
if col["name"] == colname
118101
)
102+
)
103+
if coltype is Boolean:
104+
pass
105+
# df[colname] = _fix_boolean_column(df[colname])
106+
elif coltype is DateTime:
107+
# if the first entry for this column has a decimal point,
108+
# then it is one format and we want to convert it using that format
109+
df[colname] = pd.to_datetime(
110+
df[colname], utc=True, format='ISO8601'
111+
)
112+
if len(df) > 0:
113+
if coltype is Geometry and fix_wkb is True:
114+
115+
df[colname] = fix_wkb_column(
116+
df[colname],
117+
wkb_data_start_ind=wkb_data_start_ind,
118+
n_threads=n_threads,
119+
)
119120
elif isinstance(df[colname].loc[0], Decimal) and fix_decimal is True:
120121
df[colname] = _fix_decimal_column(df[colname])
121122
return df

0 commit comments

Comments
 (0)