Skip to content

Commit 6d0c367

Browse files
committed
fix: handle input array for extract_tld
1 parent 7a5b959 commit 6d0c367

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/functions/extract_tld.cpp

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

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

2333
namespace netquack

test/sql/extract_tld.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_tld('example.com');
912
----
@@ -174,3 +177,16 @@ query I
174177
SELECT extract_tld('http:/example.com.ac:443/path');
175178
----
176179
(empty)
180+
181+
query I
182+
SELECT extract_tld(uri) from uri_list;
183+
----
184+
com
185+
com.ac
186+
com.co
187+
com
188+
com
189+
com.ac
190+
com
191+
com
192+
com.ac

0 commit comments

Comments
 (0)