Spaces:
Running
Running
fix: add calendar property to date columns in model TML
Browse filesWithout calendar: calendar, ThoughtSpot treats date ATTRIBUTE columns
as plain text and rejects .weekly/.monthly time bucketing with
"Invalid value token: weekly".
Also: get_model_columns now returns type: DATE for calendar columns
so the liveboard creator correctly identifies date columns for
granularity-based queries.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- thoughtspot_deployer.py +22 -10
thoughtspot_deployer.py
CHANGED
|
@@ -409,9 +409,11 @@ class ThoughtSpotDeployer:
|
|
| 409 |
# Map ThoughtSpot column types to SQL-like types for AI understanding
|
| 410 |
if col_type == 'MEASURE':
|
| 411 |
sql_type = 'NUMBER' # Measures are numeric
|
|
|
|
|
|
|
| 412 |
else:
|
| 413 |
-
sql_type = 'VARCHAR' #
|
| 414 |
-
|
| 415 |
columns.append({
|
| 416 |
'name': col_name,
|
| 417 |
'type': sql_type,
|
|
@@ -837,11 +839,16 @@ class ThoughtSpotDeployer:
|
|
| 837 |
# Add aggregation for measures
|
| 838 |
if aggregation:
|
| 839 |
column_def['properties']['aggregation'] = aggregation
|
| 840 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 841 |
model['model']['columns'].append(column_def)
|
| 842 |
-
|
| 843 |
# Generate YAML output with proper formatting
|
| 844 |
-
yaml_output = yaml.dump(model, default_flow_style=False, sort_keys=False,
|
| 845 |
default_style=None, indent=2, width=120)
|
| 846 |
|
| 847 |
# Validate the generated YAML
|
|
@@ -1015,16 +1022,21 @@ class ThoughtSpotDeployer:
|
|
| 1015 |
'index_type': 'DONT_INDEX'
|
| 1016 |
}
|
| 1017 |
}
|
| 1018 |
-
|
| 1019 |
if aggregation:
|
| 1020 |
column_def['properties']['aggregation'] = aggregation
|
| 1021 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1022 |
model['model']['columns'].append(column_def)
|
| 1023 |
-
|
| 1024 |
# Generate YAML output with validation
|
| 1025 |
-
yaml_output = yaml.dump(model, default_flow_style=False, sort_keys=False,
|
| 1026 |
default_style=None, indent=2, width=120)
|
| 1027 |
-
|
| 1028 |
# Fix YAML reserved word quoting - 'on' gets quoted because it's a YAML boolean
|
| 1029 |
# ThoughtSpot needs it unquoted
|
| 1030 |
yaml_output = yaml_output.replace("'on':", "on:")
|
|
|
|
| 409 |
# Map ThoughtSpot column types to SQL-like types for AI understanding
|
| 410 |
if col_type == 'MEASURE':
|
| 411 |
sql_type = 'NUMBER' # Measures are numeric
|
| 412 |
+
elif col_props.get('calendar'):
|
| 413 |
+
sql_type = 'DATE' # Calendar attribute = date column
|
| 414 |
else:
|
| 415 |
+
sql_type = 'VARCHAR' # Other attributes are typically strings
|
| 416 |
+
|
| 417 |
columns.append({
|
| 418 |
'name': col_name,
|
| 419 |
'type': sql_type,
|
|
|
|
| 839 |
# Add aggregation for measures
|
| 840 |
if aggregation:
|
| 841 |
column_def['properties']['aggregation'] = aggregation
|
| 842 |
+
|
| 843 |
+
# Add calendar property for DATE columns so ThoughtSpot enables
|
| 844 |
+
# time bucketing (.weekly, .monthly, etc.) on them
|
| 845 |
+
if self._map_data_type(col['type']) == 'DATE':
|
| 846 |
+
column_def['properties']['calendar'] = 'calendar'
|
| 847 |
+
|
| 848 |
model['model']['columns'].append(column_def)
|
| 849 |
+
|
| 850 |
# Generate YAML output with proper formatting
|
| 851 |
+
yaml_output = yaml.dump(model, default_flow_style=False, sort_keys=False,
|
| 852 |
default_style=None, indent=2, width=120)
|
| 853 |
|
| 854 |
# Validate the generated YAML
|
|
|
|
| 1022 |
'index_type': 'DONT_INDEX'
|
| 1023 |
}
|
| 1024 |
}
|
| 1025 |
+
|
| 1026 |
if aggregation:
|
| 1027 |
column_def['properties']['aggregation'] = aggregation
|
| 1028 |
+
|
| 1029 |
+
# Add calendar property for DATE columns so ThoughtSpot enables
|
| 1030 |
+
# time bucketing (.weekly, .monthly, etc.) on them
|
| 1031 |
+
if self._map_data_type(col['type']) == 'DATE':
|
| 1032 |
+
column_def['properties']['calendar'] = 'calendar'
|
| 1033 |
+
|
| 1034 |
model['model']['columns'].append(column_def)
|
| 1035 |
+
|
| 1036 |
# Generate YAML output with validation
|
| 1037 |
+
yaml_output = yaml.dump(model, default_flow_style=False, sort_keys=False,
|
| 1038 |
default_style=None, indent=2, width=120)
|
| 1039 |
+
|
| 1040 |
# Fix YAML reserved word quoting - 'on' gets quoted because it's a YAML boolean
|
| 1041 |
# ThoughtSpot needs it unquoted
|
| 1042 |
yaml_output = yaml_output.replace("'on':", "on:")
|