Skip to content

Commit 06ca43f

Browse files
committed
fix: handle input array for extract_domain
1 parent bbfd42c commit 06ca43f

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/functions/extract_domain.cpp

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

16-
if (input.empty ())
16+
for (idx_t i = 0; i < args.size (); i++)
1717
{
18-
result.SetValue (0, Value (""));
19-
return;
20-
}
21-
22-
// Extract the domain using the utility function
23-
auto domain = netquack::ExtractDomain (state, input);
18+
auto input = input_vector.GetValue (i).ToString ();
2419

25-
result.SetValue (0, Value (domain));
20+
try
21+
{
22+
// Extract the domain using the utility function
23+
auto domain = netquack::ExtractDomain (state, input);
24+
result_data[i] = StringVector::AddString (result, domain);
25+
}
26+
catch (const std::exception &e)
27+
{
28+
result_data[i] = "Error extracting domain: " + std::string (e.what ());
29+
}
30+
}
2631
}
2732

2833
namespace netquack

test/sql/extract_domain.test

Lines changed: 17 additions & 1 deletion
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_domain('example.com');
912
----
@@ -172,4 +175,17 @@ SELECT extract_domain('http:/example.com.ac/path');
172175
query I
173176
SELECT extract_domain('http:/example.com.ac:443/path');
174177
----
175-
(empty)
178+
(empty)
179+
180+
query I
181+
SELECT extract_domain(uri) from uri_list;
182+
----
183+
example.com
184+
example.com.ac
185+
example.com.co
186+
example.com
187+
example.com
188+
example.com.ac
189+
example.com
190+
example.com
191+
example.com.ac

0 commit comments

Comments
 (0)