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: UsingSpecificKeyList method #67

Merged
merged 15 commits into from
Jan 14, 2024
Merged

Conversation

kazumatsudo
Copy link
Owner

@kazumatsudo kazumatsudo commented Jan 14, 2024

Summary by CodeRabbit

  • New Features

    • Added new configuration options for analysis methods in the application settings.
    • Introduced command pattern for selecting different analysis methods.
    • Implemented new utility functions for reading JSON files and parsing JSON into specific data structures.
    • Added functionality to retrieve graph vertices based on property keys.
    • Enhanced edge query capabilities with methods to get incoming and outgoing edges for vertices.
  • Improvements

    • Updated the use case execution process with a new base trait for better exception handling.
    • Improved code readability and maintainability through refactoring and comments.
  • Bug Fixes

    • Corrected the order of columns and modified field values in test suites to align with updated specifications.
  • Tests

    • Expanded testing coverage with new test cases for edge and vertex queries.
    • Added a new test suite for analyzing specific vertices by keys in a graph database.

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

coderabbitai bot commented Jan 14, 2024

Walkthrough

The project has undergone significant changes, including the addition of error checks in build.sbt, expanded configurations in application.conf, and improvements in the codebase with new features and enhanced exception handling. New methods for interacting with the graph database have been introduced, and the test suite has been updated to cover recent changes. Overall, the project now supports more robust and specific graph analysis capabilities.

Changes

File Path Change Summary
build.sbt Added Wart.OptionPartial, Wart.PlatformDefault, Wart.SeqApply to wartremoverErrors and included Circe library dependencies.
src/main/resources/application.conf Added new configurations for analysis methods, specifically analysis_method and analysis_method_using_specific_key_list_filepath, and a new configuration related to GraphDB.
src/main/scala/Main.scala Updated imports, refactored main method with a command pattern, and added comments for analysis method selection and execution.
src/main/scala/domain/graph/GraphVertex.scala Added an id field and removed the id variable declaration within the toDml method.
src/main/scala/infrastructure/.../EdgeQuery.scala Modified EdgeQuery class to include the GraphVertex type in the getInEdgeList and getOutEdgeList methods, and added the GraphEdge type to the return type of these methods.
src/main/scala/infrastructure/.../VertexQuery.scala Imported Key from gremlin.scala and added a new method getListByPropertyKey to retrieve vertices based on property key and value.
src/main/scala/usecase/ByExhaustiveSearch.scala The class no longer extends StrictLogging, instead extends UsecaseBase, and the execute method signature has been modified.
src/main/scala/usecase/UsecaseBase.scala Introduced a trait UsecaseBase that provides a base for executing operations with exception handling.
src/main/scala/usecase/UsingSpecificKeyList.scala Introduced the UsingSpecificKeyList class for analyzing specific vertices in a graph database and added a method execute to retrieve SQL representations based on specified keys.
src/main/scala/utils/FileUtility.scala Modified to include a new readJson function and updated imports.
src/main/scala/utils/JsonUtility.scala Introduced a utility for parsing JSON strings into a specific data structure called UsingSpecificKeyListRequest using the io.circe library.
src/test/scala/infrastructure/.../EdgeQuerySpec.scala Added new test cases for the getInEdgeList and getOutEdgeList methods, expanding the testing coverage for the EdgeQuery class.
src/test/scala/infrastructure/.../VertexQuerySpec.scala Added a new test suite for the getListByPropertyKey method within the VertexQuery class.
src/test/scala/usecase/ByExhaustiveSearchSpec.scala Changed package declaration, rearranged columns, and modified field values.
src/test/scala/usecase/UsingSpecificKeyListSpec.scala Introduced a test suite for the execute method in the UsingSpecificKeyList use case, verifying the expected output based on the provided input.

🐇✨
To the code that's been changed and pruned,
With new tests and patterns, it's been finely tuned.
A rabbit hopped by, leaving footprints in dew,
Whispering of vertices and edges anew. 🌿🌟

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.

@codecov-commenter
Copy link

codecov-commenter commented Jan 14, 2024

Codecov Report

Attention: 35 lines in your changes are missing coverage. Please review.

Comparison is base (d5d8161) 80.29% compared to head (2a674a4) 72.65%.

Files Patch % Lines
src/main/scala/utils/JsonUtility.scala 0.00% 16 Missing ⚠️
src/main/scala/Main.scala 0.00% 12 Missing ⚠️
src/main/scala/usecase/UsingSpecificKeyList.scala 85.71% 4 Missing ⚠️
src/main/scala/utils/FileUtility.scala 0.00% 2 Missing ⚠️
src/main/scala/usecase/UsecaseBase.scala 50.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #67      +/-   ##
==========================================
- Coverage   80.29%   72.65%   -7.64%     
==========================================
  Files          16       19       +3     
  Lines         203      267      +64     
  Branches       24       35      +11     
==========================================
+ Hits          163      194      +31     
- Misses         40       73      +33     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d5d8161 and 031a662.
Files ignored due to path filters (1)
  • src/main/resources/using_key_list_file.json is excluded by: !**/*.json
Files selected for processing (15)
  • build.sbt (2 hunks)
  • src/main/resources/application.conf (1 hunks)
  • src/main/scala/Main.scala (3 hunks)
  • src/main/scala/domain/graph/GraphVertex.scala (2 hunks)
  • src/main/scala/infrastructure/EdgeQuery.scala (3 hunks)
  • src/main/scala/infrastructure/VertexQuery.scala (2 hunks)
  • src/main/scala/usecase/ByExhaustiveSearch.scala (2 hunks)
  • src/main/scala/usecase/UsecaseBase.scala (1 hunks)
  • src/main/scala/usecase/UsingSpecificKeyList.scala (1 hunks)
  • src/main/scala/utils/FileUtility.scala (1 hunks)
  • src/main/scala/utils/JsonUtility.scala (1 hunks)
  • src/test/scala/infrastructure/EdgeQuerySpec.scala (3 hunks)
  • src/test/scala/infrastructure/VertexQuerySpec.scala (1 hunks)
  • src/test/scala/usecase/ByExhaustiveSearchSpec.scala (4 hunks)
  • src/test/scala/usecase/UsingSpecificKeyListSpec.scala (1 hunks)
Additional comments: 18
src/main/scala/usecase/UsecaseBase.scala (1)
  • 10-26: The UsecaseBase trait provides a common structure for use cases with a protected graph traversal source and a method for exception handling. This is a good use of trait to share common functionality across different use cases.
src/main/scala/utils/FileUtility.scala (1)
  • 11-15: The readJson method in FileUtility correctly uses Scala's Using construct to ensure that the file is closed after reading, which is a good practice for resource management.
build.sbt (2)
  • 18-24: The addition of Wart.OptionPartial, Wart.PlatformDefault, and Wart.SeqApply to wartremoverErrors is a good practice to catch potential issues related to these warts at compile time.

  • 41-43: The inclusion of Circe library dependencies (circe-core, circe-generic, circe-parser) is aligned with the need for JSON processing within the application.

src/main/resources/application.conf (1)
  • 2-5: The configuration settings for analysis_method and analysis_method_using_specific_key_list_filepath are set with default values and can be overridden by environment variables, which provides flexibility for different deployment environments.
src/main/scala/utils/JsonUtility.scala (1)
  • 14-46: The parseForUsingSpecificKeyListRequest method in JsonUtility uses Circe's decoding functionality with custom decoders to handle different JSON types, which is a robust way to parse JSON into domain-specific objects.
src/main/scala/infrastructure/EdgeQuery.scala (2)
  • 27-29: The getInEdgeList method in EdgeQuery correctly retrieves incoming edges for a given vertex and maps them to the GraphEdge domain model.

  • 63-65: Similarly, the getOutEdgeList method retrieves outgoing edges for a given vertex, which is consistent with the functionality required for the new analysis method.

src/main/scala/domain/graph/GraphVertex.scala (1)
  • 20-20: The addition of the id field in the GraphVertex case class is a necessary change to align with the domain model's requirement to have an identifier for graph operations.
src/main/scala/infrastructure/VertexQuery.scala (1)
  • 56-68: The getListByPropertyKey method in VertexQuery is a valuable addition that allows retrieving vertices based on a property key and value, which is essential for the new analysis method.
src/test/scala/infrastructure/EdgeQuerySpec.scala (2)
  • 18-28: The new test cases for getInEdgeList in EdgeQuerySpec are well-constructed and ensure that the method's functionality is verified correctly.

  • 59-69: Similarly, the test cases for getOutEdgeList provide good coverage and validation for the method's expected behavior.

src/main/scala/usecase/ByExhaustiveSearch.scala (1)
  • 18-22: The ByExhaustiveSearch class now extends UsecaseBase, which is a good refactor to leverage shared functionality such as logging and exception handling.
src/test/scala/infrastructure/VertexQuerySpec.scala (1)
  • 46-71: The new test suite for getListByPropertyKey in VertexQuerySpec is comprehensive, testing for both edge cases (empty label and key) and the method's successful execution.
src/main/scala/usecase/UsingSpecificKeyList.scala (1)
  • 30-104: The UsingSpecificKeyList class is well-structured, extending UsecaseBase for shared functionality and providing a clear implementation for executing the analysis based on a specific key list.
src/main/scala/Main.scala (1)
  • 34-77: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [23-69]

The refactoring of the main method to include a command pattern for selecting analysis methods is a good design choice that enhances the maintainability and scalability of the code.

src/test/scala/usecase/UsingSpecificKeyListSpec.scala (1)
  • 18-109: The UsingSpecificKeyListSpec test suite provides thorough testing for the UsingSpecificKeyList use case, ensuring that the new functionality works as expected.
src/test/scala/usecase/ByExhaustiveSearchSpec.scala (1)
  • 27-95: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [30-109]

The updates to the ByExhaustiveSearchSpec test suite align with the changes made to the ByExhaustiveSearch use case, ensuring that the tests remain valid and effective.

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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 031a662 and aadb084.
Files selected for processing (1)
  • src/main/scala/infrastructure/EdgeQuery.scala (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/main/scala/infrastructure/EdgeQuery.scala

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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between aadb084 and 4407066.
Files selected for processing (1)
  • src/main/scala/Main.scala (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/main/scala/Main.scala

@kazumatsudo kazumatsudo merged commit abe22cc into main Jan 14, 2024
1 check passed
@kazumatsudo kazumatsudo deleted the feature/add_analysis_method branch January 14, 2024 06:35
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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4407066 and 2a674a4.
Files ignored due to path filters (2)
  • src/main/resources/using_key_list_file.json is excluded by: !**/*.json
  • src/main/resources/using_key_list_file_schema.json is excluded by: !**/*.json
Files selected for processing (1)
  • README.md (1 hunks)
Additional comments: 2
README.md (2)
  • 54-61: The Usage section has been updated to include the new analysis method 'using_specific_key_list'. It's important to ensure that the environment variable ANALYSIS_METHOD is documented correctly and that the instructions are clear for users to follow.

  • 72-108: The section 'How to change analysis method' has been added, providing instructions on how to switch between the 'by_exhaustive_search' and 'using_specific_key_list' methods. It is crucial to verify that the links to the JSON files and schema are correct and accessible.

Verification successful

The output from the shell scripts indicates that both the JSON file and schema are accessible, as they both returned an HTTP 200 status code, which means OK. Therefore, the links to the JSON files and schema in the README.md are correct and accessible.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the JSON file and schema are accessible
curl -o /dev/null -s -w "%{http_code}\n" https://github.com/kazumatsudo/GraphDB2RDB/blob/e163bdcfb7a50d5275eecfb722ac172214dd8a98/src/main/resources/using_key_list_file.json
curl -o /dev/null -s -w "%{http_code}\n" https://github.com/kazumatsudo/GraphDB2RDB/blob/e163bdcfb7a50d5275eecfb722ac172214dd8a98/src/main/resources/using_key_list_file_schema.json

Length of output: 366

Comment on lines +54 to +108
2. select analysis method
choose analysis method to search Vertex/Edge algorithm.
- "by_exhaustive_search" (default)
- "using_specific_key_list"
please see following passage if you want to change method.
```shell
% ANALYSIS_METHOD="by_exhaustive_search"
```
3. execute the script by sbt
```shell
sbt run
```
3. generate SQL files
4. generate SQL files
- sql/ddl_edge.sql
- sql/ddl_vertex.sql
- sql/insert_edge.sql
- sql/insert_vertex.sql

### How to change analysis method

#### by_exhaustive_search

##### overview

analyze all Vertices and Edges.

- pros
- no advance preparation required
- cons
- inefficient (execute full search all vertices and edges count times)

##### how to choose

no advance preparation required because it's selected by default.

#### using_specific_key_list

##### overview

analyze specific vertices searched by keys

- pros
- faster than [[ByExhaustiveSearch]] (enable to search by index)
- cons
- required to prepare search condition

##### how to choose

1. set environment variable "ANALYSIS_METHOD" to "using_specific_key_list"
```shell
% ANALYSIS_METHOD="using_specific_key_list"
```
2. set target vertex label, property key, and its values in [using_key_list_file.json](https://github.com/kazumatsudo/GraphDB2RDB/blob/e163bdcfb7a50d5275eecfb722ac172214dd8a98/src/main/resources/using_key_list_file.json)
- json schema: [using_key_list_file_schema.json](https://github.com/kazumatsudo/GraphDB2RDB/blob/e163bdcfb7a50d5275eecfb722ac172214dd8a98/src/main/resources/using_key_list_file_schema.json)

Copy link

Choose a reason for hiding this comment

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

Ensure that the documentation for setting the analysis method is clear and that the environment variable ANALYSIS_METHOD is used consistently throughout the project. It might be helpful to provide an example of how to export this variable for clarity.

- % ANALYSIS_METHOD="using_specific_key_list"
+ export ANALYSIS_METHOD="using_specific_key_list"

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
2. select analysis method
choose analysis method to search Vertex/Edge algorithm.
- "by_exhaustive_search" (default)
- "using_specific_key_list"
please see following passage if you want to change method.
```shell
% ANALYSIS_METHOD="by_exhaustive_search"
```
3. execute the script by sbt
```shell
sbt run
```
3. generate SQL files
4. generate SQL files
- sql/ddl_edge.sql
- sql/ddl_vertex.sql
- sql/insert_edge.sql
- sql/insert_vertex.sql
### How to change analysis method
#### by_exhaustive_search
##### overview
analyze all Vertices and Edges.
- pros
- no advance preparation required
- cons
- inefficient (execute full search all vertices and edges count times)
##### how to choose
no advance preparation required because it's selected by default.
#### using_specific_key_list
##### overview
analyze specific vertices searched by keys
- pros
- faster than [[ByExhaustiveSearch]] (enable to search by index)
- cons
- required to prepare search condition
##### how to choose
1. set environment variable "ANALYSIS_METHOD" to "using_specific_key_list"
```shell
% ANALYSIS_METHOD="using_specific_key_list"
```
2. set target vertex label, property key, and its values in [using_key_list_file.json](https://github.com/kazumatsudo/GraphDB2RDB/blob/e163bdcfb7a50d5275eecfb722ac172214dd8a98/src/main/resources/using_key_list_file.json)
- json schema: [using_key_list_file_schema.json](https://github.com/kazumatsudo/GraphDB2RDB/blob/e163bdcfb7a50d5275eecfb722ac172214dd8a98/src/main/resources/using_key_list_file_schema.json)
2. select analysis method
choose analysis method to search Vertex/Edge algorithm.
- "by_exhaustive_search" (default)
- "using_specific_key_list"
please see following passage if you want to change method.
```shell
% ANALYSIS_METHOD="by_exhaustive_search"
```
3. execute the script by sbt
```shell
sbt run
```
4. generate SQL files
- sql/ddl_edge.sql
- sql/ddl_vertex.sql
- sql/insert_edge.sql
- sql/insert_vertex.sql
### How to change analysis method
#### by_exhaustive_search
##### overview
analyze all Vertices and Edges.
- pros
- no advance preparation required
- cons
- inefficient (execute full search all vertices and edges count times)
##### how to choose
no advance preparation required because it's selected by default.
#### using_specific_key_list
##### overview
analyze specific vertices searched by keys
- pros
- faster than [[ByExhaustiveSearch]] (enable to search by index)
- cons
- required to prepare search condition
##### how to choose
1. set environment variable "ANALYSIS_METHOD" to "using_specific_key_list"
```shell
export ANALYSIS_METHOD="using_specific_key_list"
```
2. set target vertex label, property key, and its values in [using_key_list_file.json](https://github.com/kazumatsudo/GraphDB2RDB/blob/e163bdcfb7a50d5275eecfb722ac172214dd8a98/src/main/resources/using_key_list_file.json)
- json schema: [using_key_list_file_schema.json](https://github.com/kazumatsudo/GraphDB2RDB/blob/e163bdcfb7a50d5275eecfb722ac172214dd8a98/src/main/resources/using_key_list_file_schema.json)

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.

None yet

2 participants