Skip to content

Commit 9d6b01f

Browse files
committed
fix: handle input array for extract_query_string
1 parent 199c14a commit 9d6b01f

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/functions/extract_query.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,25 @@ namespace duckdb
77
// Function to extract the query string from a URL
88
void ExtractQueryStringFunction (DataChunk &args, ExpressionState &state, Vector &result)
99
{
10-
// Extract the URL from the input
11-
auto &url_vector = args.data[0];
12-
auto url = url_vector.GetValue (0).ToString ();
10+
// Extract the input from the arguments
11+
auto &input_vector = args.data[0];
12+
auto result_data = FlatVector::GetData<string_t> (result);
1313

14-
// Extract the query string
15-
auto query_string = netquack::ExtractQueryString (url);
14+
for (idx_t i = 0; i < args.size (); i++)
15+
{
16+
auto input = input_vector.GetValue (i).ToString ();
1617

17-
// Set the result
18-
result.SetValue (0, Value (query_string));
18+
try
19+
{
20+
// Extract the query string using the utility function
21+
auto query_string = netquack::ExtractQueryString (input);
22+
result_data[i] = StringVector::AddString (result, query_string);
23+
}
24+
catch (const std::exception &e)
25+
{
26+
result_data[i] = "Error extracting query string: " + std::string (e.what ());
27+
}
28+
};
1929
}
2030

2131
namespace netquack

test/sql/extract_query.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
require netquack
66

7+
statement ok
8+
CREATE TABLE uri_list AS SELECT * FROM read_csv('test/data/examples.csv', header=false, columns={'uri': 'VARCHAR'});
9+
710
query I
811
SELECT extract_query_string('http://example.com.ac?a=1');
912
----
@@ -28,3 +31,16 @@ query I
2831
SELECT extract_query_string('http://example.com.ac/path/?a=1');
2932
----
3033
a=1
34+
35+
query I
36+
SELECT extract_query_string(uri) from uri_list;
37+
----
38+
(empty)
39+
(empty)
40+
(empty)
41+
(empty)
42+
(empty)
43+
(empty)
44+
(empty)
45+
(empty)
46+
a=1&b=2&

0 commit comments

Comments
 (0)