Skip to content
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

add data types by janus graph #77

Merged
merged 5 commits into from
Jan 16, 2024

Conversation

kazumatsudo
Copy link
Owner

@kazumatsudo kazumatsudo commented Jan 16, 2024

#52

https://docs.janusgraph.org/schema/#property-key-data-type

Future works: Geoshape and Date

Summary by CodeRabbit

  • New Features

    • Expanded the range of column types to include Byte, Short, Float, UUID, and Character.
    • Enhanced SQL sentence generation to support new column types.
  • Tests

    • Added tests to ensure accurate conversion of new data types to SQL sentences.
    • Extended existing tests to cover new column type behaviors and interactions.

@kazumatsudo kazumatsudo self-assigned this Jan 16, 2024
Copy link

coderabbitai bot commented Jan 16, 2024

Walkthrough

The Scala codebase has been updated to include new column types (Byte, Short, Float, UUID, and Character) in both the domain definition (ColumnType.scala) and data manipulation layers (RecordValue.scala). The ColumnType object now supports these types through its apply and merge methods. Corresponding tests have been added or updated to ensure these types are correctly handled and converted to SQL sentences.

Changes

Files Change Summary
.../column/ColumnType.scala Added new column types (Byte, Short, Float, UUID, Character) and updated apply and merge methods.
.../dml/RecordValue.scala Updated to support mapping new column types to SQL values.
.../column/ColumnTypeSpec.scala & .../dml/RecordListSpec.scala Added tests for new data types and SQL sentence generation.

Poem

In the realm of code, where the data types roam,
🐇 A rabbit hopped in, making this schema its home.
With bytes and shorts, floats in tow,
UUIDs and chars, the database did grow. 🌱

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 249fc62 and c28b69f.
Files selected for processing (4)
  • src/main/scala/domain/table/ddl/column/ColumnType.scala (4 hunks)
  • src/main/scala/domain/table/dml/RecordValue.scala (2 hunks)
  • src/test/scala/domain/table/ddl/column/ColumnTypeSpec.scala (11 hunks)
  • src/test/scala/domain/table/dml/RecordListSpec.scala (2 hunks)
Additional comments: 11
src/main/scala/domain/table/dml/RecordValue.scala (1)
  • 6-14: The import statements correctly include the new ColumnType classes.
src/test/scala/domain/table/dml/RecordListSpec.scala (2)
  • 7-7: The import statement for java.util.UUID is correctly added to support the new UUID tests.
  • 83-101: The tests for converting new data types to SQL sentences are correctly implemented and should validate the functionality of the toSqlSentence method for the new types.
src/main/scala/domain/table/ddl/column/ColumnType.scala (3)
  • 3-3: The import statement for java.util.UUID is correctly added to support the new ColumnTypeUUID.
  • 30-55: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [16-51]

The new ColumnType classes (ColumnTypeByte, ColumnTypeShort, ColumnTypeFloat, ColumnTypeUUID, and ColumnTypeCharacter) are correctly defined with appropriate SQL sentence representations.

  • 102-302: The merge method is correctly extended to support the new data types and their interactions.
src/test/scala/domain/table/ddl/column/ColumnTypeSpec.scala (5)
  • 6-7: The import statement for java.util.UUID is correctly added to support the new tests for ColumnTypeUUID.
  • 12-20: The tests for the apply method correctly check the creation of new ColumnType instances for the new data types.
  • 28-42: The setup of ColumnType instances for testing the merge method is correctly implemented.
  • 90-200: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [52-137]

The tests for the merge method correctly verify the behavior when merging different ColumnType instances, including the new data types.

  • 558-565: The tests for the toSqlSentence method correctly verify the SQL sentence generation for the new data types.

Comment on lines +26 to +36
case ColumnTypeBoolean => value
case ColumnTypeByte(_) => value
case ColumnTypeShort(_) => value
case ColumnTypeInt(_) => value
case ColumnTypeLong(_) => value
case ColumnTypeFloat(_) => value
case ColumnTypeDouble(_) => value
case ColumnTypeUUID => s"\"$value\""
case ColumnTypeCharacter(_) => s"\"$value\""
case ColumnTypeString(_) => s"\"$value\""
case ColumnTypeUnknown => s"\"$value\""
Copy link

Choose a reason for hiding this comment

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

The toSqlSentence method does not properly handle the conversion of the new data types to their SQL string representations. For instance, Byte, Short, Float, and UUID types should be converted to their respective SQL string literals, not just returned as the raw value.

- case ColumnTypeByte(_)      => value
- case ColumnTypeShort(_)     => value
- case ColumnTypeFloat(_)     => value
- case ColumnTypeUUID         => s"\"$value\""
+ case ColumnTypeByte(_)      => value.toString
+ case ColumnTypeShort(_)     => value.toString
+ case ColumnTypeFloat(_)     => value.toString
+ case ColumnTypeUUID         => s"'$value'"

Additionally, UUIDs should be enclosed in single quotes, not double quotes, to conform to SQL standards.


Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
case ColumnTypeBoolean => value
case ColumnTypeByte(_) => value
case ColumnTypeShort(_) => value
case ColumnTypeInt(_) => value
case ColumnTypeLong(_) => value
case ColumnTypeFloat(_) => value
case ColumnTypeDouble(_) => value
case ColumnTypeUUID => s"\"$value\""
case ColumnTypeCharacter(_) => s"\"$value\""
case ColumnTypeString(_) => s"\"$value\""
case ColumnTypeUnknown => s"\"$value\""
case ColumnTypeBoolean => value
case ColumnTypeByte(_) => value.toString
case ColumnTypeShort(_) => value.toString
case ColumnTypeInt(_) => value
case ColumnTypeLong(_) => value
case ColumnTypeFloat(_) => value.toString
case ColumnTypeDouble(_) => value
case ColumnTypeUUID => s"'$value'"
case ColumnTypeCharacter(_) => s"\"$value\""
case ColumnTypeString(_) => s"\"$value\""
case ColumnTypeUnknown => s"\"$value\""

Comment on lines +65 to +85
case _: Boolean => ColumnTypeBoolean
case valueByte: Byte =>
ColumnTypeByte(ColumnLength(valueByte.toString.length))
case valueShort: Short =>
ColumnTypeShort(ColumnLength(valueShort.toString.length))
case valueInt: Int => ColumnTypeInt(ColumnLength(valueInt.toString.length))
case valueLong: Long =>
ColumnTypeLong(ColumnLength(valueLong.toString.length))
case valueFloat: Float =>
ColumnTypeFloat(
ColumnLength(valueFloat.toString.replaceAll("0*$", "").length)
)
case valueDouble: Double =>
ColumnTypeDouble(
ColumnLength(valueDouble.toString.replaceAll("0*$", "").length)
)
case _: Boolean => ColumnTypeBoolean
case _ => ColumnTypeUnknown // TODO: classify the type in detail
case _: UUID => ColumnTypeUUID
case _: Char => ColumnTypeCharacter(ColumnLength(1))
case valueString: String =>
ColumnTypeString(ColumnLength(valueString.length))
case _ => ColumnTypeUnknown // TODO: classify the type in detail
Copy link

Choose a reason for hiding this comment

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

The apply method in the ColumnType object should handle the conversion of Float values to a string without trailing zeros. The current implementation may include unnecessary zeros in the SQL sentence.

- ColumnLength(valueFloat.toString.replaceAll("0*$", "").length)
+ ColumnLength(valueFloat.toString.replaceAll("\\.0*$|(\\.\\d*?)0+$", "$1").length)

This change ensures that the length calculation does not include unnecessary trailing zeros after the decimal point.


Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
case _: Boolean => ColumnTypeBoolean
case valueByte: Byte =>
ColumnTypeByte(ColumnLength(valueByte.toString.length))
case valueShort: Short =>
ColumnTypeShort(ColumnLength(valueShort.toString.length))
case valueInt: Int => ColumnTypeInt(ColumnLength(valueInt.toString.length))
case valueLong: Long =>
ColumnTypeLong(ColumnLength(valueLong.toString.length))
case valueFloat: Float =>
ColumnTypeFloat(
ColumnLength(valueFloat.toString.replaceAll("0*$", "").length)
)
case valueDouble: Double =>
ColumnTypeDouble(
ColumnLength(valueDouble.toString.replaceAll("0*$", "").length)
)
case _: Boolean => ColumnTypeBoolean
case _ => ColumnTypeUnknown // TODO: classify the type in detail
case _: UUID => ColumnTypeUUID
case _: Char => ColumnTypeCharacter(ColumnLength(1))
case valueString: String =>
ColumnTypeString(ColumnLength(valueString.length))
case _ => ColumnTypeUnknown // TODO: classify the type in detail
case _: Boolean => ColumnTypeBoolean
case valueByte: Byte =>
ColumnTypeByte(ColumnLength(valueByte.toString.length))
case valueShort: Short =>
ColumnTypeShort(ColumnLength(valueShort.toString.length))
case valueInt: Int => ColumnTypeInt(ColumnLength(valueInt.toString.length))
case valueLong: Long =>
ColumnTypeLong(ColumnLength(valueLong.toString.length))
case valueFloat: Float =>
ColumnTypeFloat(
ColumnLength(valueFloat.toString.replaceAll("\\.0*$|(\\.\\d*?)0+$", "$1").length)
)
case valueDouble: Double =>
ColumnTypeDouble(
ColumnLength(valueDouble.toString.replaceAll("0*$", "").length)
)
case _: UUID => ColumnTypeUUID
case _: Char => ColumnTypeCharacter(ColumnLength(1))
case valueString: String =>
ColumnTypeString(ColumnLength(valueString.length))
case _ => ColumnTypeUnknown // TODO: classify the type in detail

@kazumatsudo kazumatsudo merged commit 3dccb3f into main Jan 16, 2024
1 check passed
@kazumatsudo kazumatsudo deleted the feature/add_data_types_by_janus_graph branch January 16, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant