1515from __future__ import annotations
1616
1717from enum import Enum
18+ import pprint
1819from typing import (
1920 TYPE_CHECKING ,
2021 ClassVar ,
@@ -107,7 +108,7 @@ class Client:
107108 _reader : BaseDataCloudReader
108109 _writer : BaseDataCloudWriter
109110 _file : DefaultFindFilePath
110- _proxy : BaseProxyClient
111+ _proxy : Optional [ BaseProxyClient ]
111112 _data_layer_history : dict [DataCloudObjectType , set [str ]]
112113
113114 def __new__ (
@@ -117,18 +118,30 @@ def __new__(
117118 proxy : Optional [BaseProxyClient ] = None ,
118119 spark_provider : Optional ["BaseSparkSessionProvider" ] = None ,
119120 ) -> Client :
121+ print ("Chuy client start 2 config:" )
122+ pprint .pprint (str (config ), indent = 4 )
123+
120124 if cls ._instance is None :
121125 cls ._instance = super ().__new__ (cls )
122126
123- spark = None
127+ print ("Chuy client here" )
128+
124129 # Initialize Readers and Writers from config
125130 # and/or provided reader and writer
126131 if reader is None or writer is None :
127132 # We need a spark because we will initialize readers and writers
128133 if config .spark_config is None :
129- raise ValueError (
130- "Spark config is required when reader/writer is not provided"
134+ # Assume BYOC Function
135+ # cls._instance._reader = None
136+ # cls._instance._writer = None
137+ cls ._instance ._file = DefaultFindFilePath ()
138+ # cls._instance._data_layer_history = None
139+ cls ._instance ._proxy = (
140+ config .proxy_config .to_object () # type: ignore
141+ if config .proxy_config is not None
142+ else None
131143 )
144+ return cls ._instance
132145
133146 provider : BaseSparkSessionProvider
134147 if spark_provider is not None :
@@ -139,22 +152,6 @@ def __new__(
139152 provider = DefaultSparkSessionProvider ()
140153
141154 spark = provider .get_session (config .spark_config )
142- elif (
143- proxy is None
144- and config .proxy_config is not None
145- and config .spark_config is not None
146- ):
147- # Both reader and writer provided; we still need spark for proxy init
148- provider = (
149- spark_provider
150- if spark_provider is not None
151- else (
152- config .spark_provider_config .to_object ()
153- if config .spark_provider_config is not None
154- else DefaultSparkSessionProvider ()
155- )
156- )
157- spark = provider .get_session (config .spark_config )
158155
159156 if config .reader_config is None and reader is None :
160157 raise ValueError (
@@ -163,44 +160,29 @@ def __new__(
163160 elif reader is None or (
164161 config .reader_config is not None and config .reader_config .force
165162 ):
166- if config .proxy_config is None :
167- raise ValueError (
168- "Proxy config is required when reader is built from config"
169- )
170- assert (
171- spark is not None
172- ) # set in "reader is None or writer is None" branch
173- assert config .reader_config is not None # ensured by branch condition
174- proxy_init = config .proxy_config .to_object (spark )
175-
176- reader_init = config .reader_config .to_object (spark )
163+ reader_init = config .reader_config .to_object (spark ) # type: ignore
177164 else :
178165 reader_init = reader
179- if proxy is not None :
180- proxy_init = proxy
181- elif config .proxy_config is None :
182- raise ValueError ("Proxy config is required when reader is provided" )
183- else :
184- assert (
185- spark is not None
186- ) # set in "both provided; proxy from config" branch
187- proxy_init = config .proxy_config .to_object (spark )
188166 if config .writer_config is None and writer is None :
189167 raise ValueError (
190168 "Writer config is required when writer is not provided"
191169 )
192170 elif writer is None or (
193171 config .writer_config is not None and config .writer_config .force
194172 ):
195- assert spark is not None # set when reader or writer from config
196- assert config .writer_config is not None # ensured by branch condition
197- writer_init = config .writer_config .to_object (spark )
173+ writer_init = config .writer_config .to_object (spark ) # type: ignore
198174 else :
199175 writer_init = writer
176+ proxy_init : Optional ["BaseProxyClient" ] = None
177+ if proxy is not None :
178+ proxy_init = proxy
179+ elif config .proxy_config is not None :
180+ proxy_init = config .proxy_config .to_object () # type: ignore
181+
200182 cls ._instance ._reader = reader_init
201183 cls ._instance ._writer = writer_init
202- cls ._instance ._file = DefaultFindFilePath ()
203184 cls ._instance ._proxy = proxy_init
185+ cls ._instance ._file = DefaultFindFilePath ()
204186 cls ._instance ._data_layer_history = {
205187 DataCloudObjectType .DLO : set (),
206188 DataCloudObjectType .DMO : set (),
@@ -260,6 +242,8 @@ def write_to_dmo(
260242 return self ._writer .write_to_dmo (name , dataframe , write_mode , ** kwargs )
261243
262244 def call_llm_gateway (self , LLM_MODEL_ID : str , prompt : str , maxTokens : int ) -> str :
245+ if self ._proxy is None :
246+ raise ValueError ("No proxy configured; set proxy or proxy_config" )
263247 return self ._proxy .call_llm_gateway (LLM_MODEL_ID , prompt , maxTokens )
264248
265249 def find_file_path (self , file_name : str ) -> Path :
0 commit comments