Files
documentdb/pg_documentdb_core/include/collation/collation.h
T
Cornelius Boateng f6d20fbf8a Merged PR 1646920: [engine][collation] Support for Arrays and Documents
### Does this PR have any customer impact? No

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Feature

### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes) No

### Are you introducing any new config? If yes, do you have tests with and without them being set? No

### ChangeLog (Refer [Template](../oss/CHANGELOG.md))

### Description
Support collation with comparison of `array` and `document` values.
Also adds support for `$in` on nested arrays and documents.

----
#### AI description  (iteration 1)
#### PR Classification
New feature: Adds support for collation-aware hashing of arrays and documents in BSON.

#### PR Summary
This pull request introduces collation-aware hashing for BSON arrays and documents, enhancing the handling of collation in hash sets. It refactors existing hash functions to accommodate collation strings and recursive hashing of nested BSON structures.
- `hashset_utils.c`: Implements collation-aware hashing functions for BSON values, including recursive handling of arrays and documents.
- `bson_expression_set_operators.c`: Replaces existing hash set creation with collation-aware hash set creation.
- `bson_dollar_operators.c`: Updates logic to use collation-aware hash sets for `$in` queries, removing unsupported scenarios.
- `hashset_utils.h`: Adds a new struct `BsonValueHashEntry` to store BSON values with collation strings.
- `collation.h`: Moves `IsBsonTypeCollationAware` function to handle collation applicability checks.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->

Related work items: #4111861, #4115239
2025-05-09 14:08:53 +08:00

53 lines
1.4 KiB
C

/*-------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* include/collation/collation.h
*
* Common declarations of functions for handling collation.
*
*-------------------------------------------------------------------------
*/
#ifndef CORE_COLLATION_H
#define CORE_COLLATION_H
#include "io/bson_core.h"
/* This value is calulated assuming all parameters in collation document is specified
* and each of them are set to the longest possible character values*/
#define MAX_ICU_COLLATION_LENGTH 110
extern bool EnableCollation;
void ParseAndGetCollationString(const bson_value_t *collationValue,
const char *collationString);
char * GetCollationSortKey(const char *collationString, char *key, int keyLength);
int StringCompareWithCollation(const char *left, uint32_t leftLength,
const char *right, uint32_t rightLength, const
char *collationStr);
static inline bool
IsCollationValid(const char *collationString)
{
return collationString != NULL && strlen(collationString) > 2;
}
static inline bool
IsCollationApplicable(const char *collationString)
{
return EnableCollation && IsCollationValid(collationString);
}
static inline bool
IsBsonTypeCollationAware(bson_type_t type)
{
return type == BSON_TYPE_UTF8 || type == BSON_TYPE_DOCUMENT ||
type == BSON_TYPE_ARRAY;
}
#endif