-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from lmangani/open_prompt
open_prompt
- Loading branch information
Showing
9 changed files
with
443 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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' }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
README.md | ||
build | ||
.idea | ||
cmake-build-debug | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.