omnata-plugin-runtime 0.10.8a255__py3-none-any.whl → 0.10.8a257__py3-none-any.whl

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.
@@ -423,6 +423,12 @@ class SnowflakeViewPart(BaseModel):
423
423
  select {', '.join([c.definition(original_name=original_name) for c in self.direct_columns()])}
424
424
  from {self.raw_table_location.get_fully_qualified_name()}
425
425
  ) """
426
+
427
+ def columns_missing(self,columns_to_check:List[str]) -> List[str]:
428
+ """
429
+ Returns a list of columns that are missing from the view part.
430
+ """
431
+ return [c for c in columns_to_check if c not in [c.original_name for c in self.columns]]
426
432
 
427
433
  class SnowflakeViewParts(BaseModel):
428
434
  """
@@ -494,7 +500,7 @@ class SnowflakeViewParts(BaseModel):
494
500
  column_name_environment=column_name_environment,
495
501
  column_name_expression=column_name_expression
496
502
  )
497
- joined_parts = []
503
+ joined_parts:List[SnowflakeViewPart] = []
498
504
  # remove the joins from the main part if they are not in the raw stream locations
499
505
  main_stream_view_part.joins = [join for join in main_stream_view_part.joins
500
506
  if join.join_stream_name in raw_stream_locations
@@ -509,21 +515,50 @@ class SnowflakeViewParts(BaseModel):
509
515
  column_name_environment=column_name_environment,
510
516
  column_name_expression=column_name_expression
511
517
  ))
512
- # For each column, the plugin can advise which streams are required for the join, which comes through as required_stream_names
518
+ # For each column, the plugin can advise which fields (of the same stream or joined) are required for the join, which comes through as referenced_columns
513
519
  # on the SnowflakeViewColumn object.
514
- # Until this generate function is called with the raw stream names, we don't know which streams the user has actually selected.
515
- # So now there's a pruning process where we remove columns from the main view part that depend on streams that are not selected
516
- for column in main_stream_view_part.columns:
517
- if column.required_stream_names:
518
- for required_stream_name in column.required_stream_names:
519
- if required_stream_name not in raw_stream_locations:
520
- logger.warning(f"Column {column.name} in stream {stream_name} requires stream {required_stream_name} to be selected, but it was not provided")
521
- main_stream_view_part.columns.remove(column)
522
- break
520
+ # Until this generate function is called with the raw stream names, we don't know which streams the user has actually selected, nor which
521
+ # fields are actually available (some may be dropped due to something like an unsupported formula).
522
+ # So now there's a pruning process where we remove columns that reference fields that are not available.
523
+ # We'll start by doing a first pass and removing unavailable columns from other streams
524
+ # then, we can do a final pass and remove columns that reference fields that are not available in the current stream
525
+ prune_count = 0
526
+ while prune(main_stream_view_part,joined_parts):
527
+ prune_count += 1
528
+ if prune_count > 10000:
529
+ raise ValueError("Pruning of columns from the view has entered an infinite loop")
523
530
 
524
531
  return cls(main_part=main_stream_view_part, joined_parts=joined_parts)
525
532
 
526
-
533
+ def prune(view_part:SnowflakeViewPart,joined_parts:List[SnowflakeViewPart]) -> bool:
534
+ """
535
+ Prunes columns from the main view part that reference fields that are not available in the joined parts.
536
+ Returns True if columns were removed, False otherwise.
537
+ """
538
+ for column in view_part.columns:
539
+ if column.referenced_columns:
540
+ for referenced_stream_name, referenced_fields in column.referenced_columns.items():
541
+
542
+ if referenced_stream_name == view_part.stream_name:
543
+ part = view_part
544
+ else:
545
+ part = next((part for part in joined_parts if part.stream_name==referenced_stream_name),None)
546
+ if part is None:
547
+ logger.warning(f"Column {column.name} in stream {view_part.stream_name} references stream {referenced_stream_name}, but it was not provided")
548
+ view_part.columns.remove(column)
549
+ return True
550
+
551
+ columns_missing_from_join = part.columns_missing(referenced_fields)
552
+ if len(columns_missing_from_join) > 0:
553
+ logger.warning(f"Column {column.name} in stream {view_part.stream_name} references fields {columns_missing_from_join} in stream {referenced_stream_name}, but they were not provided")
554
+ view_part.columns.remove(column)
555
+ return True
556
+ else:
557
+ # no columns were removed, but we need to check if the columns that are referenced are not themselves referencing other missing columns
558
+ if part != view_part:
559
+ return prune(part,joined_parts)
560
+
561
+ return False
527
562
 
528
563
  class JsonSchemaTopLevel(BaseModel):
529
564
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: omnata-plugin-runtime
3
- Version: 0.10.8a255
3
+ Version: 0.10.8a257
4
4
  Summary: Classes and common runtime components for building and running Omnata Plugins
5
5
  Author: James Weakley
6
6
  Author-email: james.weakley@omnata.com
@@ -2,12 +2,12 @@ omnata_plugin_runtime/__init__.py,sha256=MS9d1whnfT_B3-ThqZ7l63QeC_8OEKTuaYV5wTw
2
2
  omnata_plugin_runtime/api.py,sha256=baGraSMiD4Yvi3ZWrEv_TKh8Ktd1U8riBdOpe9j0Puw,8202
3
3
  omnata_plugin_runtime/configuration.py,sha256=0rfIGv8rCu8OwL7m-VOXIBjd05iyaBWRdt2h9o6scwo,46754
4
4
  omnata_plugin_runtime/forms.py,sha256=9YHJ_T17lT-rwyDaUg_0yj_YMPda4DRCw_wrvf8hE0E,19964
5
- omnata_plugin_runtime/json_schema.py,sha256=EBTIVFXFXsrV9D1M6Dhp_IJ8tO9CtUeu8swWoX6xgjg,32063
5
+ omnata_plugin_runtime/json_schema.py,sha256=6dLkOC_aeD0iwi1neCnjcwHlqj-_IfcTlVDUr-1den0,34158
6
6
  omnata_plugin_runtime/logging.py,sha256=WBuZt8lF9E5oFWM4KYQbE8dDJ_HctJ1pN3BHwU6rcd0,4461
7
7
  omnata_plugin_runtime/omnata_plugin.py,sha256=M0b6f9lKKEoEI0zf-ZwZcIPKPQTmHTIMhvcrBc94Mhg,133278
8
8
  omnata_plugin_runtime/plugin_entrypoints.py,sha256=iqGl8_nEEnPGKg3Aem4YLSQ6d5xS3ju5gq8MJbx6sCA,31968
9
9
  omnata_plugin_runtime/rate_limiting.py,sha256=qpr5esU4Ks8hMzuMpSR3gLFdor2ZUXYWCjmsQH_K6lQ,25882
10
- omnata_plugin_runtime-0.10.8a255.dist-info/LICENSE,sha256=rGaMQG3R3F5-JGDp_-rlMKpDIkg5n0SI4kctTk8eZSI,56
11
- omnata_plugin_runtime-0.10.8a255.dist-info/METADATA,sha256=GHsZU1A2Ad6KCV3l_YOzMtRjG_ywoEM1A8SE3SAWnHQ,2211
12
- omnata_plugin_runtime-0.10.8a255.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
13
- omnata_plugin_runtime-0.10.8a255.dist-info/RECORD,,
10
+ omnata_plugin_runtime-0.10.8a257.dist-info/LICENSE,sha256=rGaMQG3R3F5-JGDp_-rlMKpDIkg5n0SI4kctTk8eZSI,56
11
+ omnata_plugin_runtime-0.10.8a257.dist-info/METADATA,sha256=kfPT1sT9Jhby1FyZuD6bgVchFaJjc-ayKB7TrCtH_Uc,2211
12
+ omnata_plugin_runtime-0.10.8a257.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
13
+ omnata_plugin_runtime-0.10.8a257.dist-info/RECORD,,