MCPcopy Create free account
hub / github.com/duckdb/duckdb / ImportData

Method ImportData

tools/shell/shell.cpp:1664–1789  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1662}
1663
1664bool ShellState::ImportData(const vector<string> &args) {
1665 if (safe_mode) {
1666 PrintF(PrintOutput::STDERR, ".import cannot be used in -safe mode\n");
1667 return false;
1668 }
1669 string table_name;
1670 string file_name;
1671 unordered_map<string, string> generic_parameters;
1672 string function;
1673
1674 for (idx_t i = 1; i < args.size(); i++) {
1675 auto z = args[i].c_str();
1676 if (z[0] == '-' && z[1] == '-') {
1677 z++;
1678 }
1679 if (z[0] != '-') {
1680 if (file_name.empty()) {
1681 file_name = z;
1682 } else if (table_name.empty()) {
1683 table_name = z;
1684 } else {
1685 PrintF("ERROR: extra argument: \"%s\". Usage:\n", z);
1686 PrintHelp("import");
1687 return false;
1688 }
1689 } else if (strcmp(z, "-v") == 0) {
1690 // verbose - ignore
1691 } else if (strcmp(z, "-ascii") == 0) {
1692 PrintF(PrintOutput::STDERR, "-ascii mode is no longer supported for .import");
1693 ShellState::Exit(1);
1694 } else if (strcmp(z, "-csv") == 0) {
1695 function = "read_csv";
1696 } else if (strcmp(z, "-parquet") == 0) {
1697 function = "read_parquet";
1698 } else if (strcmp(z, "-json") == 0) {
1699 function = "read_json";
1700 } else {
1701 z++;
1702 if (i + 1 >= args.size()) {
1703 PrintF("ERROR: expected an argument for generic parameter: \"%s\". Usage:\n", z);
1704 PrintHelp("import");
1705 return false;
1706 }
1707 generic_parameters[z] = args[++i];
1708 }
1709 }
1710 if (table_name.empty()) {
1711 PrintF("ERROR: missing %s argument. Usage:\n", file_name.empty() ? "FILE" : "TABLE");
1712 PrintHelp("import");
1713 return false;
1714 }
1715 if (function.empty()) {
1716 // derive function to use from file extension
1717 // FIXME: get this list from the system somehow
1718 unordered_map<string, string> function_map;
1719 function_map[".parquet"] = "read_parquet";
1720 function_map[".csv"] = "read_csv";
1721 function_map[".tsv"] = "read_csv";

Callers 1

ImportDataFunction · 0.80

Calls 15

SQLIdentifierClass · 0.85
SQLStringClass · 0.85
c_strMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45
endMethod · 0.45
IsAutoCommitMethod · 0.45
BeginTransactionMethod · 0.45
TableInfoMethod · 0.45
QueryMethod · 0.45
HasErrorMethod · 0.45

Tested by

no test coverage detected