-- Edge cases test
|
-- This test verifies handling of edge cases
|
-- Create a test table
|
CREATE TABLE edge_test (
|
id BIGSERIAL PRIMARY KEY,
|
content TEXT
|
);
|
-- Enable vectorization
|
SELECT pgedge_vectorizer.enable_vectorization(
|
'edge_test'::regclass,
|
'content',
|
'token_based',
|
100,
|
10,
|
1536
|
);
|
NOTICE: Using primary key column: id (bigint)
|
NOTICE: Vectorization enabled: edge_test -> edge_test_content_chunks
|
NOTICE: Strategy: token_based, chunk_size: 100, overlap: 10
|
NOTICE: Processing existing rows...
|
NOTICE: Processed 0 existing rows
|
enable_vectorization
|
----------------------
|
|
(1 row)
|
|
-- Test 1: Empty string (should not create chunks)
|
INSERT INTO edge_test (content) VALUES ('');
|
SELECT COUNT(*) AS chunks_for_empty FROM edge_test_content_chunks WHERE source_id = 1;
|
chunks_for_empty
|
------------------
|
0
|
(1 row)
|
|
-- Test 2: NULL value (should not create chunks)
|
INSERT INTO edge_test (content) VALUES (NULL);
|
SELECT COUNT(*) AS chunks_for_null FROM edge_test_content_chunks WHERE source_id = 2;
|
chunks_for_null
|
-----------------
|
0
|
(1 row)
|
|
-- Test 3: Whitespace only (should not create chunks)
|
INSERT INTO edge_test (content) VALUES (' ');
|
SELECT COUNT(*) AS chunks_for_whitespace FROM edge_test_content_chunks WHERE source_id = 3;
|
chunks_for_whitespace
|
-----------------------
|
0
|
(1 row)
|
|
-- Test 4: Single word (should create 1 chunk)
|
INSERT INTO edge_test (content) VALUES ('Word');
|
SELECT COUNT(*) AS chunks_for_word FROM edge_test_content_chunks WHERE source_id = 4;
|
chunks_for_word
|
-----------------
|
1
|
(1 row)
|
|
-- Test 5: Very long text (should create multiple chunks)
|
INSERT INTO edge_test (content)
|
VALUES (repeat('This is a test sentence that will be repeated to create a very long document. ', 100));
|
SELECT COUNT(*) > 1 AS multiple_chunks FROM edge_test_content_chunks WHERE source_id = 5;
|
multiple_chunks
|
-----------------
|
t
|
(1 row)
|
|
-- Test 6: Update to empty (should delete chunks)
|
UPDATE edge_test SET content = '' WHERE id = 4;
|
SELECT COUNT(*) AS chunks_after_empty_update FROM edge_test_content_chunks WHERE source_id = 4;
|
chunks_after_empty_update
|
---------------------------
|
0
|
(1 row)
|
|
-- Test 7: Update NULL to content (should create chunks)
|
UPDATE edge_test SET content = 'New content' WHERE id = 2;
|
SELECT COUNT(*) > 0 AS chunks_after_null_update FROM edge_test_content_chunks WHERE source_id = 2;
|
chunks_after_null_update
|
--------------------------
|
t
|
(1 row)
|
|
-- Clean up
|
DELETE FROM pgedge_vectorizer.queue WHERE chunk_table = 'edge_test_content_chunks';
|
SELECT pgedge_vectorizer.disable_vectorization('edge_test'::regclass, 'content', true);
|
NOTICE: Vectorization disabled and chunk table dropped: edge_test_content_chunks
|
disable_vectorization
|
-----------------------
|
|
(1 row)
|
|
DROP TABLE edge_test;
|
-- Test 8: Custom primary key column name
|
CREATE TABLE custom_pk_test (
|
doc_id BIGSERIAL PRIMARY KEY,
|
body TEXT
|
);
|
SELECT pgedge_vectorizer.enable_vectorization(
|
'custom_pk_test'::regclass,
|
'body',
|
'token_based',
|
100,
|
10,
|
1536,
|
NULL,
|
'doc_id'
|
);
|
NOTICE: Using primary key column: doc_id (bigint)
|
NOTICE: Vectorization enabled: custom_pk_test -> custom_pk_test_body_chunks
|
NOTICE: Strategy: token_based, chunk_size: 100, overlap: 10
|
NOTICE: Processing existing rows...
|
NOTICE: Processed 0 existing rows
|
enable_vectorization
|
----------------------
|
|
(1 row)
|
|
-- Insert a document using the custom PK
|
INSERT INTO custom_pk_test (body)
|
VALUES ('This document uses a custom primary key column.');
|
-- Verify chunks were created with correct source_id
|
SELECT COUNT(*) > 0 AS chunks_created FROM custom_pk_test_body_chunks WHERE source_id = 1;
|
chunks_created
|
----------------
|
t
|
(1 row)
|
|
-- Verify queue entries exist
|
SELECT COUNT(*) > 0 AS queue_entries FROM pgedge_vectorizer.queue
|
WHERE chunk_table = 'custom_pk_test_body_chunks';
|
queue_entries
|
---------------
|
t
|
(1 row)
|
|
-- Update the document (should recreate chunks)
|
UPDATE custom_pk_test SET body = 'Updated body text.' WHERE doc_id = 1;
|
-- Clean up
|
DELETE FROM pgedge_vectorizer.queue WHERE chunk_table = 'custom_pk_test_body_chunks';
|
SELECT pgedge_vectorizer.disable_vectorization('custom_pk_test'::regclass, 'body', true);
|
NOTICE: Vectorization disabled and chunk table dropped: custom_pk_test_body_chunks
|
disable_vectorization
|
-----------------------
|
|
(1 row)
|
|
DROP TABLE custom_pk_test;
|