@@ -171,7 +171,7 @@ void ResolveLanceNamespaceAuth(ClientContext &context, const string &endpoint,
171171 string &out_bearer_token, string &out_api_key) {
172172 FillLanceNamespaceAuthFromSecrets (context, endpoint, out_bearer_token,
173173 out_api_key);
174- ( void ) options;
174+ ResolveLanceNamespaceAuthOverrides ( options, out_bearer_token, out_api_key) ;
175175}
176176
177177void ResolveLanceNamespaceAuth (ClientContext &context, const string &endpoint,
@@ -193,23 +193,57 @@ void ResolveLanceNamespaceAuth(ClientContext &context, const string &endpoint,
193193 }
194194}
195195
196- static void ResolveStorageOptions (ClientContext &context, const string &path,
197- string &out_open_path,
198- vector<string> &out_keys,
199- vector<string> &out_values) {
196+ void ResolveLanceNamespaceAuthOverrides (
197+ const unordered_map<string, Value> &options, string &out_bearer_token,
198+ string &out_api_key) {
199+ for (auto &kv : options) {
200+ if (StringUtil::CIEquals (kv.first , " token" )) {
201+ ApplyAuthOverrideValue (kv.second , out_bearer_token);
202+ continue ;
203+ }
204+ if (StringUtil::CIEquals (kv.first , " bearer_token" )) {
205+ ApplyAuthOverrideValue (kv.second , out_bearer_token);
206+ continue ;
207+ }
208+ if (StringUtil::CIEquals (kv.first , " api_key" )) {
209+ ApplyAuthOverrideValue (kv.second , out_api_key);
210+ continue ;
211+ }
212+ }
213+ }
214+
215+ void ResolveLanceStorageOptions (ClientContext &context, const string &path,
216+ string &out_open_path, vector<string> &out_keys,
217+ vector<string> &out_values) {
200218 out_open_path = path;
201219 out_keys.clear ();
202220 out_values.clear ();
203221
204- if (StringUtil::StartsWith (out_open_path, " s3://" ) ||
205- StringUtil::StartsWith (out_open_path, " s3a://" ) ||
206- StringUtil::StartsWith (out_open_path, " s3n://" )) {
207- out_open_path = LanceNormalizeS3Scheme (out_open_path);
222+ out_open_path = LanceNormalizeS3Scheme (out_open_path);
223+ if (StringUtil::StartsWith (out_open_path, " s3://" )) {
208224 LanceFillS3StorageOptionsFromSecrets (context, out_open_path, out_keys,
209225 out_values);
210226 }
211227}
212228
229+ void BuildStorageOptionPointerArrays (const vector<string> &option_keys,
230+ const vector<string> &option_values,
231+ vector<const char *> &out_key_ptrs,
232+ vector<const char *> &out_value_ptrs) {
233+ if (option_keys.size () != option_values.size ()) {
234+ throw InternalException (
235+ " Storage option keys/values size mismatch for Lance" );
236+ }
237+ out_key_ptrs.clear ();
238+ out_value_ptrs.clear ();
239+ out_key_ptrs.reserve (option_keys.size ());
240+ out_value_ptrs.reserve (option_values.size ());
241+ for (idx_t i = 0 ; i < option_keys.size (); i++) {
242+ out_key_ptrs.push_back (option_keys[i].c_str ());
243+ out_value_ptrs.push_back (option_values[i].c_str ());
244+ }
245+ }
246+
213247bool TryLanceNamespaceListTables (ClientContext &context, const string &endpoint,
214248 const string &namespace_id,
215249 const string &bearer_token,
@@ -255,16 +289,13 @@ bool TryLanceDirNamespaceListTables(ClientContext &context, const string &root,
255289 string open_root;
256290 vector<string> option_keys;
257291 vector<string> option_values;
258- ResolveStorageOptions (context, root, open_root, option_keys, option_values);
292+ ResolveLanceStorageOptions (context, root, open_root, option_keys,
293+ option_values);
259294
260295 vector<const char *> key_ptrs;
261296 vector<const char *> value_ptrs;
262- key_ptrs.reserve (option_keys.size ());
263- value_ptrs.reserve (option_values.size ());
264- for (idx_t i = 0 ; i < option_keys.size (); i++) {
265- key_ptrs.push_back (option_keys[i].c_str ());
266- value_ptrs.push_back (option_values[i].c_str ());
267- }
297+ BuildStorageOptionPointerArrays (option_keys, option_values, key_ptrs,
298+ value_ptrs);
268299
269300 auto *ptr = lance_dir_namespace_list_tables (
270301 open_root.c_str (), key_ptrs.empty () ? nullptr : key_ptrs.data (),
@@ -316,46 +347,34 @@ void *LanceOpenDataset(ClientContext &context, const string &path) {
316347 string open_path;
317348 vector<string> option_keys;
318349 vector<string> option_values;
319- ResolveStorageOptions (context, path, open_path, option_keys, option_values);
350+ ResolveLanceStorageOptions (context, path, open_path, option_keys,
351+ option_values);
320352
321353 if (option_keys.empty ()) {
322354 return lance_open_dataset (open_path.c_str ());
323355 }
324356
325357 vector<const char *> key_ptrs;
326358 vector<const char *> value_ptrs;
327- key_ptrs.reserve (option_keys.size ());
328- value_ptrs.reserve (option_values.size ());
329- for (idx_t i = 0 ; i < option_keys.size (); i++) {
330- key_ptrs.push_back (option_keys[i].c_str ());
331- value_ptrs.push_back (option_values[i].c_str ());
332- }
359+ BuildStorageOptionPointerArrays (option_keys, option_values, key_ptrs,
360+ value_ptrs);
333361 return lance_open_dataset_with_storage_options (
334362 open_path.c_str (), key_ptrs.data (), value_ptrs.data (),
335363 option_keys.size ());
336364}
337365
338- static constexpr uint64_t DEFAULT_MAX_ROWS_PER_FILE = 1024ULL * 1024ULL ;
339- static constexpr uint64_t DEFAULT_MAX_ROWS_PER_GROUP = 1024ULL ;
340- static constexpr uint64_t DEFAULT_MAX_BYTES_PER_FILE =
341- 90ULL * 1024ULL * 1024ULL * 1024ULL ;
342-
343366int64_t LanceTruncateDataset (ClientContext &context,
344367 const string &dataset_uri) {
345368 string open_path;
346369 vector<string> option_keys;
347370 vector<string> option_values;
348- ResolveStorageOptions (context, dataset_uri, open_path, option_keys,
349- option_values);
371+ ResolveLanceStorageOptions (context, dataset_uri, open_path, option_keys,
372+ option_values);
350373
351374 vector<const char *> key_ptrs;
352375 vector<const char *> value_ptrs;
353- key_ptrs.reserve (option_keys.size ());
354- value_ptrs.reserve (option_values.size ());
355- for (idx_t i = 0 ; i < option_keys.size (); i++) {
356- key_ptrs.push_back (option_keys[i].c_str ());
357- value_ptrs.push_back (option_values[i].c_str ());
358- }
376+ BuildStorageOptionPointerArrays (option_keys, option_values, key_ptrs,
377+ value_ptrs);
359378
360379 void *dataset = nullptr ;
361380 if (option_keys.empty ()) {
@@ -401,8 +420,8 @@ int64_t LanceTruncateDataset(ClientContext &context,
401420 open_path.c_str (), " overwrite" ,
402421 key_ptrs.empty () ? nullptr : key_ptrs.data (),
403422 value_ptrs.empty () ? nullptr : value_ptrs.data (), option_keys.size (),
404- DEFAULT_MAX_ROWS_PER_FILE, DEFAULT_MAX_ROWS_PER_GROUP ,
405- DEFAULT_MAX_BYTES_PER_FILE , &schema_root.arrow_schema );
423+ LANCE_DEFAULT_MAX_ROWS_PER_FILE, LANCE_DEFAULT_MAX_ROWS_PER_GROUP ,
424+ LANCE_DEFAULT_MAX_BYTES_PER_FILE , &schema_root.arrow_schema );
406425 if (!writer) {
407426 throw IOException (" Failed to open Lance writer: " + open_path +
408427 LanceFormatErrorSuffix ());
0 commit comments