Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
swilly22 committed Sep 14, 2023
1 parent cde7aa9 commit e4e4c22
Show file tree
Hide file tree
Showing 19 changed files with 168 additions and 140 deletions.
15 changes: 7 additions & 8 deletions src/errors/error_msgs.h
Expand Up @@ -81,7 +81,6 @@
#define EMSG_PARSER_ERROR "errMsg: %s line: %u, column: %u, offset: %zu errCtx: %s errCtxOffset: %zu"
#define EMSG_QUERY_WITH_MULTIPLE_STATEMENTS "Error: query with more than one statement is not supported."
#define EMSG_QUERY_TIMEOUT "Query timed out"
#define EMSG_UNABLE_TO_DROP_INDEX "ERR Unable to drop index on :%s(%s): no such index."
#define EMSG_UNKNOWN_EXECUTION_TYPE "ERR Encountered unknown query execution type."
#define EMSG_MISUSE_GRAPH_ROQUERY "graph.RO_QUERY is to be executed only on read-only queries"
#define EMSG_COULD_NOT_PARSE_QUERY "Error: could not parse query"
Expand All @@ -99,14 +98,11 @@
#define EMSG_INVALID_NOT_USAGE "Invalid usage of 'NOT' filter."
#define EMSG_ACCESS_UNDEFINED_ATTRIBUTE "Attempted to access undefined attribute"
#define EMSG_IS_MISSING "%s is missing"
#define EMSG_INDEX_ALREADY_EXISTS "Index already exists configuration can't be changed"
#define EMSG_MUST_BE "%s must be %s"
#define EMSG_NOT_SUPPORTED "%s is not supported"
#define EMSG_FULLTEXT_MIN_ARGS "Minimum number of arguments is 2"
#define EMSG_FULLTEXT_LABEL_TYPE "Label argument can be string or map"
#define EMSG_FULLTEXT_FIELD_TYPE "Field argument must be string or map"
#define EMSG_FULLTEXT_DROP_INDEX "ERR Unable to drop index on :%s: no such index."
#define EMSG_INDEX_FIELD_ALREADY_EXISTS "Index field already exists"
#define EMSG_REDISEARCH "RediSearch: %s"
#define EMSG_MANDATORY_CONSTRAINT_VIOLATION_NODE "mandatory constraint violation: node with label %s missing property %s"
#define EMSG_MANDATORY_CONSTRAINT_VIOLATION_EDGE "mandatory constraint violation: edge with relationship-type %s missing property %s";
Expand All @@ -117,10 +113,13 @@
#define EMSG_REL_DIRECTION "relDirection values must be 'incoming', 'outgoing' or 'both'"
#define EMSG_SSPATH_REQUIRED "sourceNode is required"
#define EMSG_SSPATH_INVALID_TYPE "sourceNode must be of type Node"
#define EMSG_INDEX_SUPPORT_CONSTRAINTS "Index supports constraint"
#define EMSG_QUERY_MEM_CONSUMPTION "Query's mem consumption exceeded capacity"
#define EMSG_VECTOR_TYPE_ERROR "vector%df expects an array of numbers"
#define EMSG_VECTOR_IDX_CREATE_FAIL "Failed to create vector index"
#define EMSG_IDX_INVALID_CONFIG "Invalid vector index configuration"
#define EMSG_IDX_FIELD_ALREADY_EXISTS "Attribute '%s' is already indexed"
#define EMSG_PROC_INVALID_ARGUMENTS "Invalid arguments for procedure '%s'"
#define EMSG_FULLTEXT_DROP_INDEX "ERR Unable to drop index on :%s: no such index."
#define EMSG_UNABLE_TO_DROP_INDEX "ERR Unable to drop index on :%s(%s): no such index."
#define EMSG_INDEX_SUPPORT_CONSTRAINTS "Index supports constraint"
#define EMSG_INDEX_FIELD_ALREADY_EXISTS "Attribute '%s' is already indexed"
#define EMSG_VECTOR_INDEX_INVALID_CONFIG "Invalid vector index configuration"
#define EMSG_INDEX_CANT_RECONFIG "Can not override index configuration"

1 change: 0 additions & 1 deletion src/execution_plan/optimizations/utilize_indices.c
Expand Up @@ -572,7 +572,6 @@ void utilizeIndices
// indices are utilized in three sections:
// 1. label scan followed by filter(s)
// 2. traversal followed by filter(s)
// 3. vector similarity KNN search

// convert label scan into a index scan
labelScanToIndexScan(plan, gc);
Expand Down
85 changes: 50 additions & 35 deletions src/index/index.c
Expand Up @@ -15,35 +15,43 @@

#include <stdatomic.h>

// returns a type aware name for a given field
// e.g.
// "range:age" for a range field named "age"
// "vector:location" for a vector field named "location"
// "name" for a full text field named "name"
void Index_TypedFieldName
// gets type aware index field name
void Index_RangeFieldName
(
char *type_aware_name, // [out] type aware name
IndexFieldType t, // field type
const char *name // field name
) {
ASSERT(name != NULL);
ASSERT(type_aware_name != NULL);
ASSERT(t == INDEX_FLD_FULLTEXT ||
t == INDEX_FLD_RANGE ||
t == INDEX_FLD_VECTOR);

if(t == INDEX_FLD_FULLTEXT) {
// maintain original name for full text fields
strcpy(type_aware_name, name);
} else if(t == INDEX_FLD_RANGE) {
// prefix range field name with "range:"
sprintf(type_aware_name, "range:%s", name);
} else if(t == INDEX_FLD_VECTOR) {
// prefix vector field name with "vector:"
sprintf(type_aware_name, "vector:%s", name);
} else {
assert(false && "unexpected field type");
}

// prefix range field name with "range:"
sprintf(type_aware_name, "range:%s", name);
}

// gets type aware index field name
void Index_FulltextxFieldName
(
char *type_aware_name, // [out] type aware name
const char *name // field name
) {
ASSERT(name != NULL);
ASSERT(type_aware_name != NULL);

// maintain original name for full text fields
strcpy(type_aware_name, name);
}

// gets type aware index field name
void Index_VectorFieldName
(
char *type_aware_name, // [out] type aware name
const char *name // field name
) {
ASSERT(name != NULL);
ASSERT(type_aware_name != NULL);

// prefix vector field name with "vector:"
sprintf(type_aware_name, "vector:%s", name);
}

// index structure
Expand Down Expand Up @@ -76,11 +84,11 @@ static void _Index_MergeFields
a->options.weight = b->options.weight;
a->options.nostem = b->options.nostem;
a->fulltext_name = a->name;
IndexField_SetPhonetic(a, b->options.phonetic);
IndexField_OptionsSetPhonetic(a, b->options.phonetic);
} else if(b->type & INDEX_FLD_RANGE) {
a->options.dimension = b->options.dimension;
a->range_name = rm_strdup(b->range_name);
} else if(b->type & INDEX_FLD_VECTOR) {
a->options.dimension = b->options.dimension;
a->vector_name = rm_strdup(b->vector_name);
} else {
assert(false && "unexpected field type");
Expand All @@ -95,7 +103,6 @@ static void _Index_ConstructStructure
ASSERT(idx != NULL);
ASSERT(rsIdx != NULL);

RSFieldID fieldID;
uint fields_count = array_len(idx->fields);

for(uint i = 0; i < fields_count; i++) {
Expand All @@ -118,8 +125,8 @@ static void _Index_ConstructStructure
options |= RSFLDOPT_TXTPHONETIC;
}

fieldID = RediSearch_CreateField(rsIdx, field->fulltext_name,
RSFLDTYPE_FULLTEXT, options);
RSFieldID fieldID = RediSearch_CreateField(rsIdx,
field->fulltext_name, RSFLDTYPE_FULLTEXT, options);

RediSearch_TextFieldSetWeight(rsIdx, fieldID, field->options.weight);
}
Expand All @@ -129,7 +136,9 @@ static void _Index_ConstructStructure
//----------------------------------------------------------------------

if(field->type & INDEX_FLD_VECTOR) {
fieldID = RediSearch_CreateVectorField(rsIdx, field->vector_name);
RSFieldID fieldID = RediSearch_CreateVectorField(rsIdx,
field->vector_name);

RediSearch_VectorFieldSetDim(rsIdx, fieldID, field->options.dimension);
}

Expand All @@ -141,8 +150,8 @@ static void _Index_ConstructStructure
// introduce both text, numeric and geo fields
unsigned types = RSFLDTYPE_NUMERIC | RSFLDTYPE_GEO | RSFLDTYPE_TAG;

fieldID = RediSearch_CreateField(rsIdx, field->range_name, types,
RSFLDOPT_NONE);
RSFieldID fieldID = RediSearch_CreateField(rsIdx, field->range_name,
types, RSFLDOPT_NONE);

RediSearch_TagFieldSetSeparator(rsIdx, fieldID, INDEX_SEPARATOR);
RediSearch_TagFieldSetCaseSensitive(rsIdx, fieldID, 1);
Expand All @@ -156,7 +165,7 @@ static void _Index_ConstructStructure
// for none indexable types e.g. Array introduce an additional field
// "none_indexable_fields" which will hold a list of attribute names
// that were not indexed
fieldID = RediSearch_CreateField(rsIdx, INDEX_FIELD_NONE_INDEXED,
RSFieldID fieldID = RediSearch_CreateField(rsIdx, INDEX_FIELD_NONE_INDEXED,
RSFLDTYPE_TAG, RSFLDOPT_NONE);
RediSearch_TagFieldSetSeparator(rsIdx, fieldID, INDEX_SEPARATOR);
RediSearch_TagFieldSetCaseSensitive(rsIdx, fieldID, 1);
Expand Down Expand Up @@ -300,6 +309,12 @@ RSDoc *Index_IndexGraphEntity
//----------------------------------------------------------------------

if(field->type & INDEX_FLD_VECTOR && (t & T_VECTOR)) {
// make sure entity vector dimension matches index vector dimension
if(IndexField_OptionsGetDimension(field) != SIVector_Dim(*v)) {
// vector dimension mis-match, can't index this vector
continue;
}

*doc_field_count += 1;

size_t n = SIVector_ElementsByteSize(*v);
Expand Down Expand Up @@ -674,8 +689,8 @@ bool Index_SetLanguage
ASSERT(language != NULL);

// fail if index already has language
if(idx->language != NULL) {
ErrorCtx_SetError("Can not override index configuration");
if(idx->language != NULL && strcasecmp(idx->language, language) != 0) {
ErrorCtx_SetError(EMSG_INDEX_CANT_RECONFIG);
return false;
}

Expand All @@ -694,7 +709,7 @@ bool Index_SetStopwords

// fail if index already has stopwords
if(idx->stopwords != NULL) {
ErrorCtx_SetError("Can not override index configuration");
ErrorCtx_SetError(EMSG_INDEX_CANT_RECONFIG);
return false;
}

Expand Down
20 changes: 15 additions & 5 deletions src/index/index_field.c
Expand Up @@ -132,7 +132,7 @@ void IndexField_NewVectorField
uint32_t dimension // vector dimension
) {
IndexField_Init(field, name, id, INDEX_FLD_VECTOR);
IndexField_SetDimension(field, dimension);
IndexField_OptionsSetDimension(field, dimension);
}

// clone index field
Expand Down Expand Up @@ -237,7 +237,7 @@ void IndexField_RemoveType
//------------------------------------------------------------------------------

// set index field weight
void IndexField_SetWeight
void IndexField_OptionsSetWeight
(
IndexField *field, // field to update
double weight // new weight
Expand All @@ -247,7 +247,7 @@ void IndexField_SetWeight
}

// set index field stemming
void IndexField_SetStemming
void IndexField_OptionsSetStemming
(
IndexField *field, // field to update
bool nostem // enable/disable stemming
Expand All @@ -257,7 +257,7 @@ void IndexField_SetStemming
}

// set index field phonetic
void IndexField_SetPhonetic
void IndexField_OptionsSetPhonetic
(
IndexField *field, // field to update
const char *phonetic // phonetic
Expand All @@ -270,7 +270,7 @@ void IndexField_SetPhonetic
}

// set index field vector dimension
void IndexField_SetDimension
void IndexField_OptionsSetDimension
(
IndexField *field, // field to update
uint32_t dimension // vector dimension
Expand All @@ -279,6 +279,16 @@ void IndexField_SetDimension
field->options.dimension = dimension;
}

uint32_t IndexField_OptionsGetDimension
(
const IndexField *field // field to get dimension
) {
ASSERT(field != NULL);
ASSERT(field->type & INDEX_FLD_VECTOR);

return field->options.dimension;
}

// free index field
void IndexField_Free
(
Expand Down
15 changes: 11 additions & 4 deletions src/index/index_field.h
Expand Up @@ -125,33 +125,40 @@ void IndexField_SetOptions
);

// set index field weight
void IndexField_SetWeight
void IndexField_OptionsSetWeight
(
IndexField *field, // field to update
double weight // new weight
);

// set index field stemming
void IndexField_SetStemming
void IndexField_OptionsSetStemming
(
IndexField *field, // field to update
bool nostem // enable/disable stemming
);

// set index field phonetic
void IndexField_SetPhonetic
void IndexField_OptionsSetPhonetic
(
IndexField *field, // field to update
const char *phonetic // phonetic
);

// set index field vector dimension
void IndexField_SetDimension
void IndexField_OptionsSetDimension
(
IndexField *field, // field to update
uint32_t dimension // vector dimension
);

// get vector index field dimension
// field must be a vector field
uint32_t IndexField_OptionsGetDimension
(
const IndexField *field // field to get dimension
);

// free index field
void IndexField_Free
(
Expand Down
6 changes: 3 additions & 3 deletions src/index/index_fulltext_create.c
Expand Up @@ -149,9 +149,9 @@ Index Index_FulltextCreate
IndexField field;

IndexField_NewFullTextField(&field, attr, attr_id);
IndexField_SetWeight(&field, weight);
IndexField_SetStemming(&field, nostem);
IndexField_SetPhonetic(&field, phonetic);
IndexField_OptionsSetWeight(&field, weight);
IndexField_OptionsSetStemming(&field, nostem);
IndexField_OptionsSetPhonetic(&field, phonetic);

// get schema
GraphContext *gc = QueryCtx_GetGraphCtx();
Expand Down

0 comments on commit e4e4c22

Please sign in to comment.