Skip to content

Commit 7a5b959

Browse files
committed
fix: handle input array for extract_subdomain
1 parent 5180bda commit 7a5b959

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/functions/extract_subdomain.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +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-
// Extract the sub-domain using the utility function
17-
auto subdomain = netquack::ExtractSubDomain (state, input);
16+
for (idx_t i = 0; i < args.size (); i++)
17+
{
18+
auto input = input_vector.GetValue (i).ToString ();
1819

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

2233
namespace netquack

test/sql/extract_subdomain.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_subdomain('a.example.com');
912
----
@@ -123,3 +126,16 @@ query I
123126
SELECT extract_subdomain('http:/example.com.ac:443/path');
124127
----
125128
(empty)
129+
130+
query I
131+
SELECT extract_subdomain(uri) from uri_list;
132+
----
133+
(empty)
134+
(empty)
135+
(empty)
136+
a
137+
(empty)
138+
(empty)
139+
(empty)
140+
a
141+
(empty)

0 commit comments

Comments
 (0)