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 CSV data module Implementation for Ballerina #4

Merged
merged 176 commits into from
Oct 1, 2024
Merged

Conversation

SasinduDilshara
Copy link
Contributor

@SasinduDilshara SasinduDilshara commented Jul 13, 2024

Purpose

Fixes: ballerina-platform/ballerina-library#6225
Fixes ballerina-platform/ballerina-library#6874

Following are the public apis for the module

# Converts CSV string to subtype of record array.
#
# + s - Source CSV string value
# + options - Options to be used for filtering in the projection
# + t - Target type
# + return - On success, value belonging to the given target type, else returns an `csv:Error` value.
public isolated function parseStringToRecord(string s, parseToRecordOption options = {}, typedesc<record{}[]> t = <>)
      returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external;

# Converts byte[] to subtype of record array.
#
# + s - Source CSV byte array
# + options - Options to be used for filtering in the projection
# + t - Target type
# + return - On success, value belonging to the given target type, else returns an `csv:Error` value.
public isolated function parseBytesToRecord(byte[] s, parseToRecordOption options = {}, typedesc<record{}[]> t = <>)
      returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external;

# Converts CSV byte-block-stream to subtype of record array.
#
# + s - Source CSV byte-block-stream
# + options - Options to be used for filtering in the projection
# + t - Target type
# + return - On success, value belonging to the given target type, else returns an `csv:Error` value.
public isolated function parseStreamToRecord(stream<byte[], error?> s,
            parseToRecordOption options = {}, typedesc<record{}[]> t = <>)
      returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external;

# Converts CSV string to subtype of anydata[][].
#
# + s - Source CSV string value
# + options - Options to be used for filtering in the projection
# + t - Target type
# + return - On success, value belonging to the given target type, else returns an `csv:Error` value.
public isolated function parseStringToList(string s, ParseOption options = {}, typedesc<anydata[][]> t = <>)
       returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external;

# Converts byte[] to subtype of anydata[][].
#
# + s - Source CSV byte array
# + options - Options to be used for filtering in the projection
# + t - Target type
# + return - On success, value belonging to the given target type, else returns an `csv:Error` value.
public isolated function parseBytesToList(byte[] s, ParseOption options = {}, typedesc<anydata[][]> t = <>)
       returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external;

# Converts CSV byte-block-stream to subtype of anydata[][].
#
# + s - Source CSV byte-block-stream
# + options - Options to be used for filtering in the projection
# + t - Target type
# + return - On success, value belonging to the given target type, else returns an `csv:Error` value.
public isolated function parseStreamToList(stream<byte[], error?> s,
            ParseOption options = {}, typedesc<anydata[][]> t = <>)
       returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external;

# Convert value of type record{}[] to subtype of record{}[].
#
# + s - Source Ballerina record array value
# + options - Options to be used for filtering in the projection
# + t - Target type
# + return - On success, returns value belonging to the given target type, else returns an `csv:Error` value.
public isolated function parseRecordAsRecordType(record{}[] s,
            RecordAsRecordOption options = {}, typedesc<record{}[]> t = <>)
      returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external;

# Convert value of type record{}[] to subtype of anydata[][].
#
# + s - Source Ballerina record array value
# + headerNames - The order of the header names in the source
# + options - Options to be used for filtering in the projection
# + t - Target type
# + return - On success, returns value belonging to the given target type, else returns an `csv:Error` value.
public isolated function parseRecordAsListType(record{}[] s, string[] headerNames,
            Options options = {}, typedesc<anydata[][]> t = <>)
      returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external;

# Convert value of type string[][] to subtype of record{}[].
#
# + s - Source Ballerina string array of array value
# + customHeaders - The order of the header names in the source
# + options - Options to be used for filtering in the projection
# + t - Target type
# + return - On success, returns value belonging to the given target type, else returns an `csv:Error` value.
public isolated function parseListAsRecordType(string[][] s, string[]? customHeaders = (),
            ListAsRecordOption options = {}, typedesc<record{}[]> t = <>)
      returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external;

# Convert value of type string[][] to subtype of anydata[][].
#
# + s - Source Ballerina string array of array value
# + options - Options to be used for filtering in the projection
# + t - Target type
# + return - On success, returns value belonging to the given target type, else returns an `csv:Error` value.
public isolated function parseListAsListType(string[][] s, ListAsListOption options = {}, typedesc<anydata[][]> t = <>)
      returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external;

@SasinduDilshara
Copy link
Contributor Author

@SasinduDilshara better to update gradlePluginVersion in the gradle.properties file to 2.2.4 or higher. There was an issue in gradle clean task which resulted including -SNAPSHOT jars in published github packages. ballerina-platform/plugin-gradle#138

Updated

ballerina/types.bal Outdated Show resolved Hide resolved
ballerina/csv_api.bal Show resolved Hide resolved
ballerina/csv_api.bal Outdated Show resolved Hide resolved
ballerina/csv_api.bal Outdated Show resolved Hide resolved
ballerina/csv_api.bal Outdated Show resolved Hide resolved
ballerina/types.bal Outdated Show resolved Hide resolved
ballerina/types.bal Show resolved Hide resolved
ballerina/types.bal Outdated Show resolved Hide resolved
@SasinduDilshara
Copy link
Contributor Author

Reply to #4 (comment)

I think it is better to have false, since other vendors also use like that

@MaryamZi
Copy link
Member

MaryamZi commented Sep 6, 2024

Reply to #4 (comment)

I think it is better to have false, since other vendors also use like that

Where it makes sense, IMO, we can (and should) use the ideal way supported by Ballerina. Some other frameworks may have different types/APIs because it is not possible to do this way.

Copy link
Member

@heshanpadmasiri heshanpadmasiri left a comment

Choose a reason for hiding this comment

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

Few minor nits other than that LGTM

Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Sep 25, 2024
@gimantha gimantha removed the Stale label Sep 27, 2024
@gimantha gimantha merged commit fc1571d into main Oct 1, 2024
7 checks passed
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.

Add API level documentation for CSV data Module Add CSV data module for Ballerina
9 participants