Skip to content

Commit

Permalink
Fixed issue with spec being empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Chitti-Ankith committed Apr 11, 2024
1 parent d822931 commit 48d9e8f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- run: psql test -c 'alter database test set enable_seqscan = off'

# setup the database for testing
- run: make installcheck REGRESS="pinecone_crud pinecone_medium_create pinecone_zero_vector_insert pinecone_build_after_insert" REGRESS_OPTS="--dbname=test --inputdir=./test --use-existing"
- run: make installcheck REGRESS="pinecone_crud pinecone_medium_create pinecone_zero_vector_insert pinecone_build_after_insert pinecone_invalid_config" REGRESS_OPTS="--dbname=test --inputdir=./test --use-existing"
- if: ${{ failure() }}
run: cat regression.diffs
# mac:
Expand Down
2 changes: 1 addition & 1 deletion src/pinecone/pinecone.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ IndexBulkDeleteResult *pinecone_bulkdelete(IndexVacuumInfo *info, IndexBulkDelet
IndexBulkDeleteResult *no_vacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats);

// validate
void pinecone_spec_validator(const char *spec);
void pinecone_spec_validator(const PineconeOptions *opts);
void pinecone_host_validator(const char *spec);
void validate_api_key(void);
void validate_vector_nonzero(Vector* vector);
Expand Down
3 changes: 3 additions & 0 deletions src/pinecone/pinecone_build.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ IndexBuildResult *pinecone_build(Relation heap, Relation index, IndexInfo *index
PineconeOptions *opts = (PineconeOptions *) index->rd_options;
IndexBuildResult *result = palloc(sizeof(IndexBuildResult));
VectorMetric metric = get_opclass_metric(index);
// Log spec.
pinecone_spec_validator(opts);
const char* spec = GET_STRING_RELOPTION(opts, spec);
cJSON* spec_json = cJSON_Parse(GET_STRING_RELOPTION(opts, spec));
int dimensions = TupleDescAttr(index->rd_att, 0)->atttypmod;
char* pinecone_index_name = get_pinecone_index_name(index);
Expand Down
11 changes: 5 additions & 6 deletions src/pinecone/pinecone_validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ void validate_vector_nonzero(Vector* vector) {
}


void pinecone_spec_validator(const char *spec)
void pinecone_spec_validator(const PineconeOptions *opts)
{
bool empty = strcmp(spec, "") == 0;
if (empty || cJSON_Parse(spec) == NULL)
if (opts == NULL || cJSON_Parse(GET_STRING_RELOPTION(opts, spec)) == NULL || strcmp(GET_STRING_RELOPTION(opts, spec), "") == 0)
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
(empty ? errmsg("Spec cannot be empty") : errmsg("Invalid spec: %s", spec)),
errhint("Spec should be a valid JSON object e.g. WITH (spec='{\"serverless\":{\"cloud\":\"aws\",\"region\":\"us-west-2\"}}').\n \
Refer to https://docs.pinecone.io/reference/create_index")));
errmsg("Invalid spec"),
errhint("Spec should be a valid JSON object e.g. WITH (spec='{\"serverless\":{\"cloud\":\"aws\",\"region\":\"us-west-2\"}}').\n \
Refer to https://docs.pinecone.io/reference/create_index")));
}
}

Expand Down
9 changes: 6 additions & 3 deletions test/expected/pinecone_invalid_config.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SET enable_seqscan = off;
SET client_min_messages = 'notice';
ALTER SYSTEM RESET pinecone.api_key;
SELECT pg_reload_conf();
pg_reload_conf
Expand All @@ -10,13 +11,15 @@ CREATE TABLE t (val vector(3));
CREATE INDEX i2 ON t USING pinecone (val) WITH (spec = '{"serverless":{"cloud":"aws","region":"us-west-2"}}');
ERROR: Pinecone API key not set
HINT: Set the pinecone API key using the pinecone.api_key GUC. E.g. ALTER SYSTEM SET pinecone.api_key TO 'your-api-key'
ALTER SYSTEM SET pinecone.api_key = '5b2c1031-ba58-4acc-a634-9f943d68822c';
ALTER SYSTEM SET pinecone.api_key = 'fake-key';
SELECT pg_reload_conf();
pg_reload_conf
----------------
t
(1 row)

CREATE INDEX i2 ON t USING pinecone (val);
ERROR: Spec cannot be empty
DROP TABLE t;
ERROR: Invalid spec
HINT: Spec should be a valid JSON object e.g. WITH (spec='{"serverless":{"cloud":"aws","region":"us-west-2"}}').
Refer to https://docs.pinecone.io/reference/create_index
DROP TABLE t;
3 changes: 2 additions & 1 deletion test/sql/pinecone_invalid_config.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
SET enable_seqscan = off;
SET client_min_messages = 'notice';
ALTER SYSTEM RESET pinecone.api_key;
SELECT pg_reload_conf();
CREATE TABLE t (val vector(3));
CREATE INDEX i2 ON t USING pinecone (val) WITH (spec = '{"serverless":{"cloud":"aws","region":"us-west-2"}}');
ALTER SYSTEM SET pinecone.api_key = '5b2c1031-ba58-4acc-a634-9f943d68822c';
ALTER SYSTEM SET pinecone.api_key = 'fake-key';
SELECT pg_reload_conf();
CREATE INDEX i2 ON t USING pinecone (val);
DROP TABLE t;

0 comments on commit 48d9e8f

Please sign in to comment.