Skip to content

Commit

Permalink
chore: rename extension libpostal -> postal
Browse files Browse the repository at this point in the history
This makes it
- shorter
- distinct from the wrapped project,
  which I think is good for users, but also helps with development because
  it makes it more clear if I'm referring
  to libpostal or to this extension
  • Loading branch information
NickCrews committed Nov 29, 2023
1 parent d2168fb commit 6e40e0b
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/MainDistributionPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
vcpkg_commit: a42af01b72c28a8e1d7b48107b33e4f286a55ef6
duckdb_version: v0.9.2
extension_name: libpostal
extension_name: postal

duckdb-stable-deploy:
name: Deploy extension binaries
Expand All @@ -27,6 +27,6 @@ jobs:
secrets: inherit
with:
duckdb_version: v0.9.2
extension_name: libpostal
extension_name: postal
deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}
deploy_versioned: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 2.8.12)

# Set extension name here
set(TARGET_NAME libpostal)
set(TARGET_NAME postal)

set(EXTENSION_NAME ${TARGET_NAME}_extension)
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
Expand All @@ -13,7 +13,7 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBPOSTAL REQUIRED libpostal)
include_directories(${LIBPOSTAL_INCLUDE_DIRS})

set(EXTENSION_SOURCES src/libpostal_extension.cpp)
set(EXTENSION_SOURCES src/postal_extension.cpp)

build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ ifeq ($(GEN),ninja)
endif

#### Configuration for this extension
EXTENSION_NAME=LIBPOSTAL
EXTENSION_NAME=POSTAL
EXTENSION_FLAGS=\
-DDUCKDB_EXTENSION_NAMES="libpostal" \
-DDUCKDB_EXTENSION_NAMES="postal" \
-DDUCKDB_EXTENSION_${EXTENSION_NAME}_PATH="$(PROJ_DIR)" \
-DDUCKDB_EXTENSION_${EXTENSION_NAME}_LOAD_TESTS=1 \
-DDUCKDB_EXTENSION_${EXTENSION_NAME}_INCLUDE_PATH="$(PROJ_DIR)src/include" \
Expand Down Expand Up @@ -54,7 +54,7 @@ libpostal-configure:
sudo make install

#### Main build
# For regular CLI build, we link the libpostal extension directly into the DuckDB executable
# For regular CLI build, we link the extension directly into the DuckDB executable
CLIENT_FLAGS=-DDUCKDB_EXTENSION_${EXTENSION_NAME}_SHOULD_LINK=1

debug:
Expand Down Expand Up @@ -88,8 +88,8 @@ test_debug: debug
./build/debug/$(TEST_PATH) "$(PROJ_DIR)test/*"

#### Client tests
DEBUG_EXT_PATH='$(PROJ_DIR)build/debug/extension/libpostal/libpostal.duckdb_extension'
RELEASE_EXT_PATH='$(PROJ_DIR)build/release/extension/libpostal/libpostal.duckdb_extension'
DEBUG_EXT_PATH='$(PROJ_DIR)build/debug/extension/postal/postal.duckdb_extension'
RELEASE_EXT_PATH='$(PROJ_DIR)build/release/extension/postal/postal.duckdb_extension'
test_js: test_debug_js
test_debug_js: debug_js
cd duckdb/tools/nodejs && ${EXTENSION_NAME}_EXTENSION_BINARY_PATH=$(DEBUG_EXT_PATH) npm run test-path -- "../../../test/nodejs/**/*.js"
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ The main binaries that will be built are:
```sh
./build/release/duckdb
./build/release/test/unittest
./build/release/extension/libpostal/libpostal.duckdb_extension
./build/release/extension/postal/postal.duckdb_extension
```
- `duckdb` is the binary for the duckdb shell with the extension code automatically loaded.
- `unittest` is the test runner of duckdb. Again, the extension is already linked into the binary.
- `libpostal.duckdb_extension` is the loadable binary as it would be distributed.
- `postal.duckdb_extension` is the loadable binary as it would be distributed.

## Running the extension
To run the extension code, simply start the shell with `./build/release/duckdb`.

Now we can use the features from the extension directly in DuckDB. The template contains a single scalar function `libpostal()` that takes a string arguments and returns a string:
Now we can use the features from the extension directly in DuckDB. The template contains a single scalar function `postal()` that takes a string arguments and returns a string:
```
D select libpostal('Jane') as result;
D select postal('Jane') as result;
┌───────────────┐
│ result │
│ varchar │
Expand Down Expand Up @@ -81,6 +81,6 @@ DuckDB. To specify a specific version, you can pass the version instead.

After running these steps, you can install and load your extension using the regular INSTALL/LOAD commands in DuckDB:
```sql
INSTALL libpostal
LOAD libpostal
INSTALL postal
LOAD postal
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace duckdb {

class LibpostalExtension : public Extension {
class PostalExtension : public Extension {
public:
void Load(DuckDB &db) override;
std::string Name() override;
Expand Down
26 changes: 13 additions & 13 deletions src/libpostal_extension.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define DUCKDB_EXTENSION_MAIN

#include "libpostal_extension.hpp"
#include "postal_extension.hpp"
#include "duckdb.hpp"
#include "duckdb/common/exception.hpp"
#include "duckdb/common/string_util.hpp"
Expand All @@ -12,12 +12,12 @@

namespace duckdb {

inline void LibpostalScalarFun(DataChunk &args, ExpressionState &state, Vector &result) {
inline void PostalScalarFun(DataChunk &args, ExpressionState &state, Vector &result) {
auto &name_vector = args.data[0];
UnaryExecutor::Execute<string_t, string_t>(
name_vector, result, args.size(),
[&](string_t name) {
return StringVector::AddString(result, "Libpostal "+name.GetString()+" 🐥");;
return StringVector::AddString(result, "Postal "+name.GetString()+" 🐥");;
});
}

Expand All @@ -43,34 +43,34 @@ static void LoadInternal(DatabaseInstance &instance) {
exit(EXIT_FAILURE);
}

auto libpostal_scalar_function = ScalarFunction("libpostal", {LogicalType::VARCHAR}, LogicalType::VARCHAR, LibpostalScalarFun);
ExtensionUtil::RegisterFunction(instance, libpostal_scalar_function);
auto f = ScalarFunction("postal", {LogicalType::VARCHAR}, LogicalType::VARCHAR, PostalScalarFun);
ExtensionUtil::RegisterFunction(instance, f);

auto libpostal_parse_address = ScalarFunction("libpostal_parse_address", {LogicalType::VARCHAR}, LogicalType::VARCHAR, ParseAddress);
ExtensionUtil::RegisterFunction(instance, libpostal_parse_address);
auto f = ScalarFunction("parse_address", {LogicalType::VARCHAR}, LogicalType::VARCHAR, ParseAddress);
ExtensionUtil::RegisterFunction(instance, f);

// Teardown (only called once at the end of your program)
// libpostal_teardown();
// libpostal_teardown_parser();
}

void LibpostalExtension::Load(DuckDB &db) {
void PostalExtension::Load(DuckDB &db) {
LoadInternal(*db.instance);
}
std::string LibpostalExtension::Name() {
return "libpostal";
std::string PostalExtension::Name() {
return "postal";
}

} // namespace duckdb

extern "C" {

DUCKDB_EXTENSION_API void libpostal_init(duckdb::DatabaseInstance &db) {
DUCKDB_EXTENSION_API void postal_init(duckdb::DatabaseInstance &db) {
duckdb::DuckDB db_wrapper(db);
db_wrapper.LoadExtension<duckdb::LibpostalExtension>();
db_wrapper.LoadExtension<duckdb::PostalExtension>();
}

DUCKDB_EXTENSION_API const char *libpostal_version() {
DUCKDB_EXTENSION_API const char *postal_version() {
return duckdb::DuckDB::LibraryVersion();
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/nodejs/libpostal_test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
var duckdb = require('../../duckdb/tools/nodejs');
var assert = require('assert');

describe(`libpostal extension`, () => {
describe(`postal extension`, () => {
let db;
let conn;
before((done) => {
db = new duckdb.Database(':memory:', {"allow_unsigned_extensions":"true"});
conn = new duckdb.Connection(db);
conn.exec(`LOAD '${process.env.QUACK_EXTENSION_BINARY_PATH}';`, function (err) {
conn.exec(`LOAD '${process.env.POSTAL_EXTENSION_BINARY_PATH}';`, function (err) {
if (err) throw err;
done();
});
});

it('libpostal function should return expected string', function (done) {
db.all("SELECT libpostal('Sam') as value;", function (err, res) {
it('postal function should return expected string', function (done) {
db.all("SELECT postal('Sam') as value;", function (err, res) {
if (err) throw err;
assert.deepEqual(res, [{value: "Libpostal Sam 🐥"}]);
assert.deepEqual(res, [{value: "Postal Sam 🐥"}]);
done();
});
});
Expand Down
12 changes: 6 additions & 6 deletions test/python/libpostal_test.py → test/python/postal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@

DEFAULT_EXTENSION_PATH = (
Path(__file__).parent.parent.parent
/ "build/debug/extension/libpostal/libpostal.duckdb_extension"
/ "build/debug/extension/postal/postal.duckdb_extension"
)


# Get a fresh connection to DuckDB with the libpostal extension binary loaded
# Get a fresh connection to DuckDB with the extension binary loaded
@pytest.fixture
def duckdb_conn():
extension_binary = os.environ.get(
"LIBPOSTAL_EXTENSION_BINARY_PATH", DEFAULT_EXTENSION_PATH
"POSTAL_EXTENSION_BINARY_PATH", DEFAULT_EXTENSION_PATH
)
conn = duckdb.connect("", config={"allow_unsigned_extensions": "true"})
conn.execute(f"load '{extension_binary}'")
return conn


def test_libpostal(duckdb_conn):
duckdb_conn.execute("SELECT libpostal('Sam') as value;")
def test_postal(duckdb_conn):
duckdb_conn.execute("SELECT postal('Sam') as value;")
res = duckdb_conn.fetchall()
assert res[0][0] == "Libpostal Sam 🐥"
assert res[0][0] == "Postal Sam 🐥"
18 changes: 0 additions & 18 deletions test/sql/libpostal.test

This file was deleted.

18 changes: 18 additions & 0 deletions test/sql/postal.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# name: test/sql/postal.test
# description: test postal extension
# group: [postal]

# Before we load the extension, this will fail
statement error
SELECT postal('Sam');
----
Catalog Error: Scalar Function with name postal does not exist!

# Require statement will ensure this test is run with this extension loaded
require postal

# Confirm the extension works
query I
SELECT postal('Sam');
----
Postal Sam 🐥

0 comments on commit 6e40e0b

Please sign in to comment.