malikrafsan / Polypheny-DotNet-Driver

Driver for .NET using the Polypheny Prism Query Interface
Apache License 2.0
0 stars 0 forks source link

[Main] Progress Report For Google Summer of Code Program #1

Open malikrafsan opened 4 months ago

malikrafsan commented 4 months ago

Description

This issue will contain and track about the progress of this project (Polypheny .NET Driver)

malikrafsan commented 4 months ago

2 May - 12 May

  1. Explore about GRPC project using .NET
    • Create a GRPC server and a GRPC client driver that uses the same proto files. The proto files are shared on those two projects so that to simulate the shared proto interface. The GRPC client driver is then published in NuGet and installed on different projects that use the client driver package. By this, we can simulate the end goal of Polypheny .NET driver -> creating a client driver for a client project
    • link: https://github.com/malikrafsan/Grpc-Dotnet-Server-Client/

Screenshot from 2024-05-20 21-01-57

  1. Create a custom package using .NET and publish the package to NuGet

Screenshot from 2024-05-20 20-56-46

malikrafsan commented 4 months ago

12 May - 19 May

  1. Propose project structure and unit test
    • Add a PR that contains the proposed project structure, which contains two major directories: PolyphenyDotNetDriver and PolyphenyDotNetDriver.Tests. We split the project into the source code for the package and the test code for the package. By splitting, in the test code, we can access the source code as a client. This is done so that we can have separation of concern and (AFAIK) the client doesn't need to install the test code
    • PR Link: https://github.com/polypheny/Polypheny-DotNet-Driver/pull/1

image

  1. Connect the project with Polypheny Prism Protobuf definition
    • This PR adds a git-submodule definition that refers to Polypheny Prism Protobuf
    • We can generate the C# files from the protobuf contract running shell file generate_pb.sh
    • The generated C# files are then added to the main program to test whether the generated C# files can be used
    • The test code is then added a simple new unit test to check whether we can access the generated C# successfully through the main program
    • PR Link: https://github.com/polypheny/Polypheny-DotNet-Driver/pull/2

image

malikrafsan commented 3 months ago

21 May - 29 May

Research possible alternatives to structure the code

From what I understand, .NET provides the interface and abstract class for the database connector as well -> IDbDataAdapter, IDbConnection, IDbCommand, IDbDataParameter, IDbTransaction

I think there are 3 possible approaches that we can take

We discussed this and decided to pick the first and second options

Build Polypheny server locally

Previously I used release results. However, this is incompatible with the current code. The solution is that we need to build the Polypheny server locally. I build it using Polypheny Control

Screenshot from 2024-05-27 15-55-31 Screenshot from 2024-05-27 15-56-01

Able to run the Golang and Python tests successfully using the built Polypheny server

Screenshot from 2024-05-29 12-08-49 Screenshot from 2024-05-29 12-09-15

Add Polypheny Connection and its test that has capabilities to open and close connection with the server, and ping the database server

The PR: https://github.com/polypheny/Polypheny-DotNet-Driver/pull/3

image

malikrafsan commented 3 months ago

30 May - 5 June

Optimize The Code Performance By Converting to Async Function

After learning directly from MySQL Connector codes, it would be better to change the function to be a wrapper of the async function. For example, in the Open method, we implement it by calling the OpenAsync method and await the result then return it. Here I try to do it by using the async variants of Read and Write methods from TCP NetworkStream. The implication is that Send and Receive methods using protobuf are async methods as well. By this approach, we convert these methods into wrappers of async methods:

Screenshot from 2024-06-04 21-54-56

Add Execute Non Query Functionalities And Its Test

Class DbCommand from .NET which we inherit, uses two interfaces to send SQL commands to the database, which are ExecuteNonQuery and ExecuteDbDataReader. ExecuteNonQuery is used for data manipulation and schema definition, whereas ExecuteDbDataReader is used for query.

In this progress, we have implemented the ExecuteNonQuery method successfully with its test as well.

Add Prepared Functionality for Execute Non Query

In this progress, we also have implemented the prepared functionality to include parameters in the SQL command.

Here is the screenshot of the test. In the test, we insert a row by passing parameterized values using ? mark Screenshot from 2024-06-04 22-01-12

Migrate From Prism Import to Nuget Package

In this progress, we also migrate from importing Prism Protobuf manually to importing from Nuget Package. By this approach, we centralized the management of the Prism Protobuf to the Nuget package and do not manage it directly in the driver code

Screenshot from 2024-06-04 22-05-26

malikrafsan commented 3 months ago

6 June - 19 June

Add Execute Query Functionality

As mentioned previously, Class DbCommand from .NET which we inherit, uses two interfaces to send SQL commands to the database, which are ExecuteNonQuery and ExecuteDbDataReader. ExecuteNonQuery is used for data manipulation and schema definition, whereas ExecuteDbDataReader is used for query.

In this progress, we have implemented the ExecuteDbDataReader and its related methods. Those methods will return PolyphenyDataReader which inherits from DbDataReader. This class allows the user to read the query result from the database

Add Test Case For Execute Query Functionality

In this progress, we also add the test case for the Execute Query Functionality. The test case will test whether the driver is able to query the database. We add two test cases.

  1. Check whether the driver is able to query predefined table
  2. Check whether the driver is able to query recently inserted data from a recently created table

The left image shows the first case whereas the middle image shows the second case. The test result is shown in the right image Screenshot from 2024-06-19 12-21-22

malikrafsan commented 2 months ago

20 June - 26 June

Add Execute Query Mongo

Polypheny also supports document-based databases. In this implementation, we add an interface for executing Mongo-like queries for document-based databases. This interface will return an array of dictionaries, representing document data

Add Test Case For Execute Query Mongo

In this progress, we also add the test case for the Execute Query Mongo. The test case will test whether the driver is able to query the document-based database. We add two test cases.

  1. Check whether the driver is able to query the document-based data

Screenshot from 2024-06-26 15-36-43

Minor Addition for Unimplemented Methods and Code Readability

In this progress, we also change and implement minor additions, such as

malikrafsan commented 2 months ago

27 June - 3 July

Add PolyphenyTransaction

As Polypheny supports SQL databases, one of the main features of SQL databases is ACID properties. To ensure ACID properties, a transaction feature is needed to be implemented. This week, we implemented PolyphenyTransaction. PolyphenyTransaction is a class for managing transaction features. We also made adjustments needed for this feature to the other classes as well. By implementing this feature, we can have multiple queries that work as one unit (one transaction).

This class has two methods, which are Commit and Rollback. Commit is used to make the changes in that transaction permanent. Whereas Rollback is used to cancel all of the changes in that transaction.

Add Test Cases For Transaction Feature

In this week, we also add test cases for the transaction feature. These test cases are used to test the Commit and Rollback interfaces. Commit is tested with a scenario in which we select a table that is inserted and committed in a transaction. Rollback is tested with a scenario in which we select a table that is inserted and rollbacked.

Screenshot from 2024-07-03 11-07-41

malikrafsan commented 2 months ago

4 July - 17 July

Research and Add The Mechanism for Calculating and Visualizing Code Coverage

To increase the reliability of the driver, we need to add more tests to ensure that the code works properly and can be maintained easily. To quantify the testing, we can add code coverage to the driver. We need to visualize the code coverage properly to better view the code coverage result. We use the NUnit package to calculate the code coverage and output the report in cobertura format. We visualize the report by using reportgenerator library, which outputs HTML and related files. Here is the visualization of the current report

Screenshot from 2024-07-17 17-59-06

Add Test Cases for PolyphenyDataReader and ProtoHelper

We also add the test cases for the PolyphenyDataReader and ProtoHelper classes. This is still ongoing progress as there are still a lot of classes and methods that need to be tested

malikrafsan commented 1 month ago

18 July - 24 July

Refactor Code using Interface and Dependency Injection Pattern

In order to increase the reliability of the driver, we need to increase the test for the driver. One metric that is useful for this case is code coverage. Previously, we have set up the mechanism to calculate and visualize the code coverage. However, some codes are still low in code coverage because it is harder to test.

In order to make it easier to test and in turn increase the code coverage, we refactor the code using interface pattern and dependency injection pattern. With this pattern, we can easily make unit tests using mock interfaces that work as intended without being dependent on other parts of the code. Here is an example

Screenshot from 2024-08-14 12-07-30

Increase Code Coverage

As previously mentioned, we intend to increase the code coverage. After doing the refactor, it is much easier to add new unit tests to cover other parts of the code that are harder to test using end-to-end testing. We have successfully increase the code coverage to be 90% for line coverage and 78% for branch coverage

Screenshot from 2024-08-14 12-10-21

Add Demo Project

To make it easier for the developers to use this driver, we added a demo project that contains a lot of code examples to use this driver. By doing this, the developers who want to use this driver can take a look at the code examples and customize them by their needs. The demo project can be access at here

Add Project Documentation

In addition to the demo project, we also added more explanation in the README file of the project. This README file also can make it easier for the developers who want to use this driver. The README file covers several stuff for the project, ranging from how to setup, how to use, code examples, and how to test the driver.