sofhiaazzhr commited on
Commit
307a7b1
·
1 Parent(s): c749544

detect XLSX by filename, not table count

Browse files
Files changed (1) hide show
  1. src/query/executor/tabular.py +17 -6
src/query/executor/tabular.py CHANGED
@@ -20,6 +20,7 @@ from typing import Any
20
  import pandas as pd
21
 
22
  from ...catalog.models import Catalog, Source, Table
 
23
  from ...middlewares.logging import get_logger
24
  from ..compiler.pandas import CompiledPandas, PandasCompiler
25
  from ..ir.models import QueryIR
@@ -131,9 +132,19 @@ class TabularExecutor(BaseExecutor):
131
  def _resolve_blob_name(source: Source, table: Table) -> str:
132
  """Map source.location_ref + table → the Parquet blob name to download.
133
 
134
- Convention:
135
- CSV / single-sheet Parquet → ``{user_id}/{document_id}.parquet``
136
- XLSX (multi-sheet) ``{user_id}/{document_id}__{table.name}.parquet``
 
 
 
 
 
 
 
 
 
 
137
  """
138
  if not source.location_ref.startswith(_AZ_BLOB_PREFIX):
139
  raise ValueError(
@@ -145,9 +156,9 @@ def _resolve_blob_name(source: Source, table: Table) -> str:
145
  if len(parts) != 2 or not parts[0] or not parts[1]:
146
  raise ValueError(f"Malformed az_blob location_ref: {source.location_ref!r}")
147
  user_id, document_id = parts
148
- if len(source.tables) == 1:
149
- return f"{user_id}/{document_id}.parquet"
150
- return f"{user_id}/{document_id}__{table.name}.parquet"
151
 
152
 
153
  def _load_and_apply(blob_bytes: bytes, compiled: CompiledPandas) -> pd.DataFrame:
 
20
  import pandas as pd
21
 
22
  from ...catalog.models import Catalog, Source, Table
23
+ from ...knowledge.parquet_service import parquet_blob_name
24
  from ...middlewares.logging import get_logger
25
  from ..compiler.pandas import CompiledPandas, PandasCompiler
26
  from ..ir.models import QueryIR
 
132
  def _resolve_blob_name(source: Source, table: Table) -> str:
133
  """Map source.location_ref + table → the Parquet blob name to download.
134
 
135
+ Delegates to ``parquet_service.parquet_blob_name`` so the same naming
136
+ convention (and ``_safe_sheet_name`` sanitization) is used on both the
137
+ write side (ingestion) and the read side (query execution).
138
+
139
+ CSV / Parquet → ``{user_id}/{document_id}.parquet``
140
+ XLSX → ``{user_id}/{document_id}__{safe_sheet}.parquet``
141
+ (writer always uploads with sheet suffix for XLSX,
142
+ regardless of sheet count — see processing_service
143
+ `_build_excel_documents`)
144
+
145
+ XLSX is detected via ``Source.name`` (the original filename). This relies
146
+ on the upload pipeline preserving the file extension, which it does today
147
+ because `Document.filename` is set once at upload and never renamed.
148
  """
149
  if not source.location_ref.startswith(_AZ_BLOB_PREFIX):
150
  raise ValueError(
 
156
  if len(parts) != 2 or not parts[0] or not parts[1]:
157
  raise ValueError(f"Malformed az_blob location_ref: {source.location_ref!r}")
158
  user_id, document_id = parts
159
+ is_xlsx = source.name.lower().endswith(".xlsx")
160
+ sheet_name = table.name if is_xlsx else None
161
+ return parquet_blob_name(user_id, document_id, sheet_name)
162
 
163
 
164
  def _load_and_apply(blob_bytes: bytes, compiled: CompiledPandas) -> pd.DataFrame: