dbt-cube-sync 0.1.0a3__tar.gz → 0.1.0a4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dbt-cube-sync might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dbt-cube-sync
3
- Version: 0.1.0a3
3
+ Version: 0.1.0a4
4
4
  Summary: Synchronization tool for dbt models to Cube.js schemas and BI tools
5
5
  Author: Ponder
6
6
  Requires-Python: >=3.9,<4.0
@@ -337,12 +337,26 @@ class SupersetConnector(BaseConnector):
337
337
  'count_distinct': 'COUNT(DISTINCT'
338
338
  }
339
339
 
340
+ # Remove Cube.js ${} syntax and convert to plain SQL column references
341
+ cleaned_expression = self._clean_cube_expression(sql_expression)
342
+
340
343
  agg_func = agg_mapping.get(agg_type, 'SUM')
341
344
 
342
345
  if agg_type == 'count_distinct':
343
- return f"{agg_func} {sql_expression})"
346
+ return f"{agg_func} {cleaned_expression})"
344
347
  else:
345
- return f"{agg_func}({sql_expression})"
348
+ return f"{agg_func}({cleaned_expression})"
349
+
350
+ def _clean_cube_expression(self, expression: str) -> str:
351
+ """Convert Cube.js expressions to SQL column references for Superset"""
352
+ import re
353
+
354
+ # Remove ${} syntax - convert ${column_name} to column_name
355
+ cleaned = re.sub(r'\$\{([^}]+)\}', r'\1', expression)
356
+
357
+ # Handle more complex expressions like arithmetic
358
+ # Keep parentheses and operators but clean column references
359
+ return cleaned
346
360
 
347
361
  def _create_or_update_dataset(self, schema_info: Dict[str, Any]) -> int:
348
362
  """Create a new dataset or update existing one"""
@@ -506,37 +520,41 @@ class SupersetConnector(BaseConnector):
506
520
 
507
521
  def _update_metrics(self, existing_metrics: List[dict], measures: List[dict]) -> List[dict]:
508
522
  """Update metrics with new measures"""
509
- # Clean existing metrics
523
+ # Clean existing metrics and create a lookup by name
510
524
  updated_metrics = []
525
+ existing_metric_names = {}
526
+
511
527
  for metric in existing_metrics:
512
528
  clean_metric = {k: v for k, v in metric.items()
513
529
  if k not in ['created_on', 'changed_on', 'uuid']}
530
+ existing_metric_names[metric.get('metric_name')] = len(updated_metrics)
514
531
  updated_metrics.append(clean_metric)
515
532
 
516
- # Add new metrics
517
- existing_metric_names = {m.get('metric_name') for m in existing_metrics}
518
- added_count = 0
519
-
533
+ # Add or update metrics
520
534
  for measure in measures:
521
535
  metric_name = measure['metric_name']
522
536
 
523
- if metric_name not in existing_metric_names:
524
- new_metric = {
525
- 'metric_name': metric_name,
526
- 'verbose_name': measure['verbose_name'],
527
- 'expression': measure['expression'],
528
- 'description': measure['description'],
529
- 'metric_type': 'simple',
530
- 'currency': None,
531
- 'd3format': None,
532
- 'extra': None,
533
- 'warning_text': None
534
- }
535
- updated_metrics.append(new_metric)
536
- print(f" ✓ Prepared '{metric_name}': {measure['expression']}")
537
- added_count += 1
537
+ new_metric = {
538
+ 'metric_name': metric_name,
539
+ 'verbose_name': measure['verbose_name'],
540
+ 'expression': measure['expression'],
541
+ 'description': measure['description'],
542
+ 'metric_type': 'simple',
543
+ 'currency': None,
544
+ 'd3format': None,
545
+ 'extra': None,
546
+ 'warning_text': None
547
+ }
548
+
549
+ if metric_name in existing_metric_names:
550
+ # Update existing metric
551
+ index = existing_metric_names[metric_name]
552
+ updated_metrics[index].update(new_metric)
553
+ print(f" ✓ Updated '{metric_name}': {measure['expression']}")
538
554
  else:
539
- print(f" ⊘ Skipping '{metric_name}' (already exists)")
555
+ # Add new metric
556
+ updated_metrics.append(new_metric)
557
+ print(f" ✓ Added '{metric_name}': {measure['expression']}")
540
558
 
541
559
  return updated_metrics
542
560
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dbt-cube-sync"
3
- version = "0.1.0a3"
3
+ version = "0.1.0a4"
4
4
  description = "Synchronization tool for dbt models to Cube.js schemas and BI tools"
5
5
  authors = ["Ponder"]
6
6
  readme = "README.md"