Skip to content

UDT #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

UDT #168

wants to merge 13 commits into from

Conversation

PiotrJunior
Copy link
Contributor

@PiotrJunior PiotrJunior commented Mar 25, 2025

Adds UserDefinedType.
Currently not all Integration tests are enabled, as UDT don't support typeHints for now and resultMetadata is not yet supported.

@wprzytula
Copy link
Contributor

Just FYI @PiotrJunior: I'm not going to review this as long as it has conflicts with the base branch.

@PiotrJunior PiotrJunior force-pushed the tuple-type branch 3 times, most recently from 1810f26 to b396da9 Compare April 14, 2025 15:37
@PiotrJunior PiotrJunior force-pushed the udt branch 2 times, most recently from 49dcad6 to 02cd0aa Compare April 14, 2025 16:51
@PiotrJunior PiotrJunior force-pushed the udt branch 3 times, most recently from b9092ef to 725fd64 Compare April 15, 2025 07:46
@PiotrJunior PiotrJunior marked this pull request as draft April 15, 2025 07:47
@PiotrJunior PiotrJunior marked this pull request as ready for review April 15, 2025 07:47
@adespawn
Copy link
Collaborator

It this PR ready for the review?

@wprzytula
Copy link
Contributor

It this PR ready for the review?

I doubt it is. It has conflicts and the CI is failing.

Comment on lines +157 to +165
//
// This will be fixed at a later time, as it requires more investigation into how UDT works.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ When? As UDT support is added in this PR, I believe you should be now able to solve the problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is regarding typeGuessing and I think @adespawn can elaborate on this topic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be fixed in next PR.

adespawn added 2 commits May 29, 2025 12:50
Removes CqlTypeClass, to reduce the overhead from it's type.
This means, that array will be treated as ambiguous types.
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for a new UserDefinedType (UDT) across multiple parts of the codebase including unit tests, integration tests, type wrappers, and request handling. Key changes include:

  • Adding new test cases for UDT in unit and integration tests.
  • Enhancing Rust type wrappers to support UDT with additional fields and associated methods.
  • Updating JavaScript utilities and driver code to properly encode, decode, and wrap UDTs.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/unit/query-parameter-tests.js Added UDT test case to verify proper parameter encoding.
test/unit/cql-value-wrapper-tests.js Introduced test for retrieving UDT type values from the N-API.
test/integration/supported/client-execute-tests.js Adjusted and commented out UDT/tuple tests; added TODOs for missing features.
test/integration/supported/client-execute-prepared-tests.js Updated handling of UDT/tuple tests in prepared statement flows.
src/types/type_wrappers.rs Extended ComplexType with UDT-specific fields and helper methods.
src/tests/result_tests.rs Added test function for UDT value wrapper functionality.
src/tests/request_values_tests.rs Added UDT mapping and sample UDT value in tests.
src/result.rs Implemented N-API conversion for UDT in CqlValueWrapper.
src/requests/parameter_wrappers.rs Added function to convert UDT parameters from JS arrays to CqlValue.
lib/types/cql-utils.js Enhanced UDT encoding logic for driver parameter wrapping.
examples/DataStax/udt/udt-insert-select.js Updated example to use dynamic unique key and replication strategy changes.
Comments suppressed due to low confidence (2)

test/integration/supported/client-execute-tests.js:1183

  • Instead of commenting out tests with block comments, consider using a test skip function (e.g., 'xit' or an equivalent) to clearly indicate that the test is intentionally disabled until UDT support is complete.
            // TODO: Add support for column information retrieval

test/integration/supported/client-execute-prepared-tests.js:1408

  • To enhance clarity and maintainability, use a formal test skip mechanism to disable tests temporarily rather than commenting them out.
        // Test for UDT and Tuple support

Comment on lines +144 to +148
* @param {Object} value
* @param {rust.ComplexType} type
* @returns {Array<rust.ComplexType|Array<Array<String|any>>>} Returns tuple: [rust.ComplexType, [[fieldName, fieldValue]]]
*/
function encodeUdt(value, type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns tuple: [rust.ComplexType, [[fieldName, fieldValue]]]

Really? Double Array? Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because, this function returns array of tuples of field name and value, but in JS tuple is represented as array

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain this thoroughly in a comment.

Comment on lines +1183 to 1187
// TODO: Add support for column information retrieval
/* vit("2.1", "should retrieve column information", function (done) {
const client = setupInfo.client;
client.execute(
util.format(selectQuery, sampleId),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adespawn @ZuzaOsa @PiotrJunior Do described limitations (unimplemented parts of the driver's API) include missing fields/properties (not only methods)?

Comment on lines +1305 to +1306
// TODO: Add type guessing for UDT and Tuple
/* vit(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Why isn't this implemented in this PR yet?
❓ When is it going to be implemented?
🔧 If there's no issue for this missing feature yet, please open it!

Uuid = 0x000C,
Varint = 0x000E,
Custom = 0x0000,
Unprovided = 0x0070,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ How can you be sure that there's no type that uses this value? Where did you take it from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those codes are taken from CQL protocol specification

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm specifically asking about the Unprovided variant.

wprzytula and others added 3 commits June 4, 2025 14:55
Installing packages with `pip` using the `--user` flag may be the way
to avoid permission issues. Let's try this out.
…ci-ccm-permission-errors

CI: attempt to fix ccm permission errors
Expand ComplexType to include UDTs.
@PiotrJunior PiotrJunior force-pushed the udt branch 2 times, most recently from 97c4090 to 9b001dd Compare June 10, 2025 09:52
Adds support for converting udt responses to a JavaScript object.
Add tests for converting CQL values to JavaScript values
Adds support for converting JS UDT type into Rust UDT type.
Adds tests for converting JS UDT into Rust CQL values.
Add proper type IDs to the type wrappers.
IDs match those in CQL protocol.
This is will be useful for testing metadata.
}
const element = getWrapped(
types[i],
value[names[i]] !== undefined ? value[names[i]] : null, // Undefineds should be treated as nulls, so we convert them to nulls.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value[names[i]] !== undefined ? value[names[i]] : null, // Undefineds should be treated as nulls, so we convert them to nulls.
value[names[i]] !== undefined ? value[names[i]] : null, // Undefined values should be treated as null value.

Comment on lines +122 to +128
match pair.get::<Undefined>(1) {
Ok(Some(_)) | Ok(None) => res.push((name, None)),
_ => {
let value = cql_value_from_napi_value(&typ, &pair, 1)?;
res.push((name, Some(value)));
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we attempt to get undefined, if we can only receive null?

Comment on lines +309 to +310
keyspace: _,
name: _,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we loose this information, or did DSX not provide those information in result?

Comment on lines +183 to +193
.udt_metadata
.as_ref()
.map(|udt| udt.keyspace.clone())
.expect("Expected keyspace for UDT")
.clone(),
name: typ
.udt_metadata
.as_ref()
.map(|udt| udt.name.clone())
.expect("Expected name for UDT")
.clone(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did DataStax provide any possibility to have UDT in unprepared queries?

From what I can see expecting keyspace and name limits it's usage only to prepared queries

Comment on lines +183 to +187
.udt_metadata
.as_ref()
.map(|udt| udt.keyspace.clone())
.expect("Expected keyspace for UDT")
.clone(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you use helper function you added: get_udt_keyspace?

@adespawn adespawn force-pushed the second-iteration branch 2 times, most recently from 16128e9 to 6300c7f Compare June 17, 2025 09:58
@adespawn adespawn mentioned this pull request Jun 17, 2025
Base automatically changed from second-iteration to main June 25, 2025 12:49
@adespawn adespawn dismissed ZuzaOsa’s stale review June 25, 2025 12:49

The base branch was changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Types Custom types used by the database
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants