Skip to content

Commit

Permalink
Merge pull request #1 from lmangani/open_prompt
Browse files Browse the repository at this point in the history
open_prompt
  • Loading branch information
lmangani authored Oct 20, 2024
2 parents f63f2f0 + 527f5ca commit 8902140
Show file tree
Hide file tree
Showing 9 changed files with 443 additions and 224 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/MainDistributionPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ jobs:
with:
duckdb_version: main
ci_tools_version: main
extension_name: http_client
extension_name: open_prompt

duckdb-stable-build:
name: Build extension binaries
uses: duckdb/extension-ci-tools/.github/workflows/[email protected]
with:
duckdb_version: v1.1.1
ci_tools_version: v1.1.1
extension_name: http_client
extension_name: open_prompt

duckdb-stable-deploy:
name: Deploy extension binaries
Expand All @@ -35,5 +35,5 @@ jobs:
secrets: inherit
with:
duckdb_version: v1.1.1
extension_name: http_client
extension_name: open_prompt
deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
README.md
build
.idea
cmake-build-debug
Expand Down
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 3.5)

# Set extension name here
set(TARGET_NAME http_client)
set(TARGET_NAME open_prompt)

# DuckDB's extension distribution supports vcpkg. As such, dependencies can be added in ./vcpkg.json and then
# used in cmake with find_package. Feel free to remove or replace with other dependencies.
Expand All @@ -14,7 +14,7 @@ set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
project(${TARGET_NAME})
include_directories(src/include duckdb/third_party/httplib)

set(EXTENSION_SOURCES src/http_client_extension.cpp)
set(EXTENSION_SOURCES src/open_prompt_extension.cpp)

if(MINGW)
set(OPENSSL_USE_STATIC_LIBS TRUE)
Expand Down
4 changes: 2 additions & 2 deletions extension_config.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# This file is included by DuckDB's build system. It specifies which extension to load

# Extension from this repo
duckdb_extension_load(http_client
duckdb_extension_load(open_prompt
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}
LOAD_TESTS
)

# Any extra extensions that should be built
duckdb_extension_load(json)
# duckdb_extension_load(json)
216 changes: 0 additions & 216 deletions src/http_client_extension.cpp

This file was deleted.

91 changes: 91 additions & 0 deletions src/include/http_metadata_cache.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#pragma once

#include "duckdb/common/atomic.hpp"
#include "duckdb/common/chrono.hpp"
#include "duckdb/common/list.hpp"
#include "duckdb/common/mutex.hpp"
#include "duckdb/common/string.hpp"
#include "duckdb/common/types.hpp"
#include "duckdb/common/unordered_map.hpp"
#include "duckdb/main/client_context.hpp"
#include "duckdb/main/client_context_state.hpp"

#include <stddef.h>
#include <string>

namespace duckdb {

struct HTTPMetadataCacheEntry {
idx_t length;
time_t last_modified;
};

// Simple cache with a max age for an entry to be valid
class HTTPMetadataCache : public ClientContextState {
public:
explicit HTTPMetadataCache(bool flush_on_query_end_p, bool shared_p)
: flush_on_query_end(flush_on_query_end_p), shared(shared_p) {};

void Insert(const string &path, HTTPMetadataCacheEntry val) {
if (shared) {
lock_guard<mutex> parallel_lock(lock);
map[path] = val;
} else {
map[path] = val;
}
};

void Erase(string path) {
if (shared) {
lock_guard<mutex> parallel_lock(lock);
map.erase(path);
} else {
map.erase(path);
}
};

bool Find(string path, HTTPMetadataCacheEntry &ret_val) {
if (shared) {
lock_guard<mutex> parallel_lock(lock);
auto lookup = map.find(path);
if (lookup != map.end()) {
ret_val = lookup->second;
return true;
} else {
return false;
}
} else {
auto lookup = map.find(path);
if (lookup != map.end()) {
ret_val = lookup->second;
return true;
} else {
return false;
}
}
};

void Clear() {
if (shared) {
lock_guard<mutex> parallel_lock(lock);
map.clear();
} else {
map.clear();
}
}

//! Called by the ClientContext when the current query ends
void QueryEnd(ClientContext &context) override {
if (flush_on_query_end) {
Clear();
}
}

protected:
mutex lock;
unordered_map<string, HTTPMetadataCacheEntry> map;
bool flush_on_query_end;
bool shared;
};

} // namespace duckdb
Loading

0 comments on commit 8902140

Please sign in to comment.