MCPcopy Create free account
hub / github.com/activeloopai/deeplake / create_table

Method create_table

cpp/deeplake_pg/table_storage.cpp:670–968  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

668}
669
670void table_storage::create_table(const std::string& table_name, Oid table_id, TupleDesc tupdesc)
671{
672 // Acquire global DDL lock to prevent concurrent CREATE/DROP TABLE operations (also needed for deeplake)
673 pg::table_ddl_lock_guard ddl_lock;
674
675 pg::utils::memory_context_switcher context_switcher(TopMemoryContext);
676
677 auto options = pg::table_options::current();
678 pg::table_options::current().reset();
679 auto [schema_name, simple_table_name] = split_table_name(table_name);
680 if (table_exists(table_id) || table_exists(table_name)) {
681 return;
682 }
683
684 std::string dataset_path;
685 // Use provided dataset path or construct default path
686 if (!options.dataset_path().empty()) {
687 if (!pg::allow_custom_paths) {
688 ereport(
689 ERROR,
690 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
691 errmsg("Custom dataset_path is disabled"),
692 errhint("Set deeplake.allow_custom_paths=on or omit dataset_path and configure deeplake.root_path")));
693 }
694 // Explicit path provided via WITH clause
695 dataset_path = options.dataset_path();
696 } else {
697 // Get session root path if set, otherwise fall back to default root.
698 auto session_root = session_credentials::get_root_path();
699 if (session_root.empty()) {
700 session_root = pg::utils::get_deeplake_root_directory();
701 }
702 // Construct path: root_dir/schema_name/table_name
703 dataset_path = session_root + "/" + schema_name + "/" + simple_table_name;
704 }
705
706 // Get credentials from current session
707 auto creds = session_credentials::get_credentials();
708
709 table_data td(table_id, table_name, CreateTupleDescCopy(tupdesc), dataset_path, creds);
710 PinTupleDesc(td.get_tuple_descriptor());
711
712 // Catalog-only mode: the dataset already exists on S3 (known from the catalog).
713 // Skip all S3 operations — just register in pg_class (done by DDL) and our tables_ map.
714 // Still write to pg_deeplake_tables so other code paths can discover the table locally.
715 if (is_catalog_only_create()) {
716 save_table_metadata(td);
717 tables_.emplace(table_id, std::move(td));
718 up_to_date_ = false;
719 return;
720 }
721
722 bool ds_exists = false;
723 try {
724 auto creds_for_exists = creds;
725 ds_exists = deeplake_api::exists(dataset_path, std::move(creds_for_exists)).get_future().get();
726 } catch (const base::exception& e) {
727 ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("%s", e.what())));

Callers 1

relation_set_new_nodeMethod · 0.80

Calls 15

split_table_nameFunction · 0.85
log_infoFunction · 0.85
is_file_domain_typeFunction · 0.85
is_image_domain_typeFunction · 0.85
is_video_domain_typeFunction · 0.85
get_tuple_descriptorMethod · 0.80
get_futureMethod · 0.80
whatMethod · 0.80
open_datasetMethod · 0.80
urlMethod · 0.80
num_columnsMethod · 0.80

Tested by

no test coverage detected