sunholo 0.125.0__py3-none-any.whl → 0.125.1__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.
@@ -584,7 +584,8 @@ class AlloyDBClient:
584
584
 
585
585
  async def create_table_from_schema(self, table_name: str, schema_data: dict, users: list = None):
586
586
  """
587
- Creates or ensures a table exists based on the structure of the provided schema data.
587
+ Creates or ensures a table exists based on the structure of the provided schema data,
588
+ with special handling for expandable lists.
588
589
 
589
590
  Args:
590
591
  table_name (str): Name of the table to create
@@ -596,22 +597,32 @@ class AlloyDBClient:
596
597
  """
597
598
  # Generate column definitions from schema data
598
599
  columns = []
600
+
599
601
  for key, value in schema_data.items():
600
- if isinstance(value, dict):
601
- # For nested objects, store as JSONB
602
- columns.append(f'"{key}" JSONB')
603
- elif isinstance(value, list):
604
- # For arrays, store as JSONB
605
- columns.append(f'"{key}" JSONB')
606
- elif isinstance(value, int):
607
- columns.append(f'"{key}" INTEGER')
608
- elif isinstance(value, float):
609
- columns.append(f'"{key}" NUMERIC')
610
- elif isinstance(value, bool):
611
- columns.append(f'"{key}" BOOLEAN')
602
+ # Check if this is a specially marked expandable list
603
+ if isinstance(value, dict) and value.get("__is_expandable_list__", False):
604
+ # Handle expandable lists - we need to examine the first item to determine column types
605
+ items = value.get("items", [])
606
+
607
+ # Add an index column for this list
608
+ columns.append(f'"{key}_index" INTEGER')
609
+
610
+ if items and isinstance(items[0], dict):
611
+ # If the first item is a dictionary, we need to create columns for all its keys
612
+ sample_item = items[0]
613
+ # Flatten the dictionary with the key as prefix
614
+ flattened_item = self._flatten_dict_for_schema(sample_item, key, "_")
615
+
616
+ # Add columns for all keys in the flattened dictionary
617
+ for item_key, item_value in flattened_item.items():
618
+ item_column = self._get_column_definition(item_key, item_value)
619
+ columns.append(item_column)
620
+ else:
621
+ # If items are simple values, just add a column for the list key itself
622
+ columns.append(self._get_column_definition(key, items[0] if items else None))
612
623
  else:
613
- # Default to TEXT for strings and other types
614
- columns.append(f'"{key}" TEXT')
624
+ # Regular handling for non-list fields
625
+ columns.append(self._get_column_definition(key, value))
615
626
 
616
627
  # Add metadata columns
617
628
  columns.extend([
@@ -651,7 +662,64 @@ class AlloyDBClient:
651
662
 
652
663
  return result
653
664
 
654
- def flatten_dict(self, nested_dict, parent_key='', separator='.'):
665
+ def _get_column_definition(self, key, value):
666
+ """
667
+ Helper method to get SQL column definition from a key and value.
668
+
669
+ Args:
670
+ key (str): The column name
671
+ value: The value to determine the column type
672
+
673
+ Returns:
674
+ str: SQL column definition
675
+ """
676
+ if value is None:
677
+ # For unknown types (None), default to TEXT
678
+ return f'"{key}" TEXT'
679
+ elif isinstance(value, dict):
680
+ # For nested objects, store as JSONB
681
+ return f'"{key}" JSONB'
682
+ elif isinstance(value, list):
683
+ # For arrays, store as JSONB
684
+ return f'"{key}" JSONB'
685
+ elif isinstance(value, int):
686
+ return f'"{key}" INTEGER'
687
+ elif isinstance(value, float):
688
+ return f'"{key}" NUMERIC'
689
+ elif isinstance(value, bool):
690
+ return f'"{key}" BOOLEAN'
691
+ else:
692
+ # Default to TEXT for strings and other types
693
+ return f'"{key}" TEXT'
694
+
695
+ def _flatten_dict_for_schema(self, nested_dict, parent_key='', separator='.'):
696
+ """
697
+ Flatten a nested dictionary for schema creation.
698
+
699
+ Args:
700
+ nested_dict (dict): The nested dictionary to flatten
701
+ parent_key (str): The parent key for the current recursion level
702
+ separator (str): The separator to use between key levels
703
+
704
+ Returns:
705
+ dict: A flattened dictionary
706
+ """
707
+ flattened = {}
708
+
709
+ for key, value in nested_dict.items():
710
+ # Create the new key with parent_key if it exists
711
+ new_key = f"{parent_key}{separator}{key}" if parent_key else key
712
+
713
+ # If value is a dictionary, recursively flatten it
714
+ if isinstance(value, dict):
715
+ flattened.update(self._flatten_dict_for_schema(value, new_key, separator))
716
+ else:
717
+ # For simple values, just add them with the new key
718
+ flattened[new_key] = value
719
+
720
+ return flattened
721
+
722
+ def _flatten_dict(self, nested_dict, parent_key='', separator='.'):
655
723
  """
656
724
  Flatten a nested dictionary into a single-level dictionary with dot notation for keys.
657
725
 
@@ -671,7 +739,7 @@ class AlloyDBClient:
671
739
 
672
740
  # If value is a dictionary, recursively flatten it
673
741
  if isinstance(value, dict):
674
- flattened.update(self.flatten_dict(value, new_key, separator))
742
+ flattened.update(self._flatten_dict(value, new_key, separator))
675
743
  # Handle lists containing dictionaries or other values
676
744
  elif isinstance(value, list):
677
745
  # Mark lists for special processing during database insertion
@@ -729,7 +797,7 @@ class AlloyDBClient:
729
797
  # Add the current item from the primary list
730
798
  if isinstance(item, dict):
731
799
  # If it's a dictionary, flatten it with the primary key as prefix
732
- flattened_item = self.flatten_dict(item, primary_list_key, "_")
800
+ flattened_item = self._flatten_dict(item, primary_list_key, "_")
733
801
  row_data.update(flattened_item)
734
802
  else:
735
803
  # If it's a simple value, just add it with the list key
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sunholo
3
- Version: 0.125.0
3
+ Version: 0.125.1
4
4
  Summary: Large Language Model DevOps - a package to help deploy LLMs to the Cloud.
5
5
  Author-email: Holosun ApS <multivac@sunholo.com>
6
6
  License: Apache License, Version 2.0
@@ -60,7 +60,7 @@ sunholo/components/retriever.py,sha256=Wmchv3huAM4w7DIS-a5Lp9Hi7M8pE6vZdxgseiT9S
60
60
  sunholo/components/vectorstore.py,sha256=k7GS1Y5c6ZGXSDAJvyCes6dTjhDAi0fjGbVLqpyfzBc,5918
61
61
  sunholo/database/__init__.py,sha256=bpB5Nk21kwqYj-qdVnvNgXjLsbflnH4g-San7OHMqR4,283
62
62
  sunholo/database/alloydb.py,sha256=x1zUMB-EVWbE2Zvp4nAs2Z-tB_kOZmS45H2lwVHdYnk,11678
63
- sunholo/database/alloydb_client.py,sha256=s9P57k4RC_b0Dpy0rzTUHs-h9yj3ClFYL52JzXUYeU8,31487
63
+ sunholo/database/alloydb_client.py,sha256=IszkoMgL_OBBg6YCWBIq2v5blIX9TApdlxPgNREDt1o,34429
64
64
  sunholo/database/database.py,sha256=VqhZdkXUNdvWn8sUcUV3YNby1JDVf7IykPVXWBtxo9U,7361
65
65
  sunholo/database/lancedb.py,sha256=DyfZntiFKBlVPaFooNN1Z6Pl-LAs4nxWKKuq8GBqN58,715
66
66
  sunholo/database/static_dbs.py,sha256=8cvcMwUK6c32AS2e_WguKXWMkFf5iN3g9WHzsh0C07Q,442
@@ -168,9 +168,9 @@ sunholo/vertex/init.py,sha256=1OQwcPBKZYBTDPdyU7IM4X4OmiXLdsNV30C-fee2scQ,2875
168
168
  sunholo/vertex/memory_tools.py,sha256=tBZxqVZ4InTmdBvLlOYwoSEWu4-kGquc-gxDwZCC4FA,7667
169
169
  sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
170
170
  sunholo/vertex/type_dict_to_json.py,sha256=uTzL4o9tJRao4u-gJOFcACgWGkBOtqACmb6ihvCErL8,4694
171
- sunholo-0.125.0.dist-info/licenses/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
172
- sunholo-0.125.0.dist-info/METADATA,sha256=NyIZ1U8SH9vnTS0ECdCISbh2o7fp0HVBMsOKRvwipkE,10001
173
- sunholo-0.125.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
174
- sunholo-0.125.0.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
175
- sunholo-0.125.0.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
176
- sunholo-0.125.0.dist-info/RECORD,,
171
+ sunholo-0.125.1.dist-info/licenses/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
172
+ sunholo-0.125.1.dist-info/METADATA,sha256=KFpMxsW_gucPhBoSwzZU8UHg9tnFEMe3Lv254hgsKqE,10001
173
+ sunholo-0.125.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
174
+ sunholo-0.125.1.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
175
+ sunholo-0.125.1.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
176
+ sunholo-0.125.1.dist-info/RECORD,,