Skip to content

Commit f918c71

Browse files
committed
fix: handle input array for extract_host
1 parent 06ca43f commit f918c71

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/functions/extract_host.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,23 @@ namespace duckdb
99
{
1010
// Extract the input from the arguments
1111
auto &input_vector = args.data[0];
12-
auto input = input_vector.GetValue (0).ToString ();
12+
auto result_data = FlatVector::GetData<string_t> (result);
1313

14-
// Extract the host using the utility function
15-
auto host = netquack::ExtractHost (input);
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 (host));
18+
try
19+
{
20+
// Extract the host using the utility function
21+
auto host = netquack::ExtractHost (input);
22+
result_data[i] = StringVector::AddString (result, host);
23+
}
24+
catch (const std::exception &e)
25+
{
26+
result_data[i] = "Error extracting host: " + std::string (e.what ());
27+
}
28+
}
1929
}
2030

2131
namespace netquack

test/sql/extract_host.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_host('http://example.com.ac/path');
912
----
@@ -63,3 +66,16 @@ query I
6366
SELECT extract_host('rsync://rpki.example.com/path');
6467
----
6568
rpki.example.com
69+
70+
query I
71+
SELECT extract_host(uri) from uri_list;
72+
----
73+
example.com
74+
example.com.ac
75+
example.com.co
76+
a.example.com
77+
example.com
78+
example.com.ac
79+
example.com
80+
a.example.com
81+
example.com.ac

0 commit comments

Comments
 (0)