-
-
Notifications
You must be signed in to change notification settings - Fork 397
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
[DB] Import or load data from an external CSV file to a table #680
[DB] Import or load data from an external CSV file to a table #680
Comments
Suggestion: (WITHOUT HEADERS)Try this for "WITH HEADERS": (replace the relevant line)
|
Worth adding to this Page: |
Hi @authorjapps @nirmalchandra, I find very useful the ability to interact with the database. I will like to contribute to this issue. I have reviewed the repository and docs to get understanding of how zerocode works as it is my first contribution. I noted that the Sample-DB-SQL-Executor depends on Spring and specific DBMSs, and other classes like This is a proposal for discussion before starting the implementation:
{
"scenarioName": "Sample interaction with the db executor ( data from AC2)",
"steps": [
{
"name": "Loading a csv file",
"url": "org.jsmart.zerocode.core.db.DbSqlExecutor",
"operation": "loadCsv",
"request": {
"tableName": "players",
"csvSource": "path/db_sample.csv",
"noHeaders" : false, //<-- this is the default value, guess that using header may be the most used
"nullString" : "" //<-- used to insert null values, this is the default value
},
"verify": { } //<-- no data returned, log and fail the step if anything fails
},
{
"name": "Read the loaded data using SQL",
"url": "org.jsmart.zerocode.core.db.DbSqlExecutor",
"operation": "executeQuery",
"request": {
"sqlStatement": "SELECT id, name, age FROM players WHERE age > ? ORDER BY age ASC",
"sqlParameters" : [ 23 ]
},
"verify": {
"rows.SIZE": 2,
"rows": [
{ "id": 1002, "name": "Devaldo", "age": 24 },
{ "id": 1003, "name": "Trevaldo", "age": 35 }
]
}
}
]
} |
@javiertuya 👋 , Thanks for the suggestions! Great thought! All of it has great details and sounds like great Idea. |
Also, please take into consideration in this ticket(if possible or in a new ticket later), how to LOAD/IMPORT data or execute code from a private URL(unlike GitHub (I think better to separete out this feature into a new ticket and impl in a separte PR) |
@javiertuya , I have captured almost all of it now into the ticket. Please proceed with implementation when ready. (mainly AC5, AC6 with minor updates) |
@authorjapps Great, working on it.
I was referring to using the same approach to get the content of the csvSource. This could result in some code to refactor later. |
Oh, ok. This will make the assertions mechanism very easy and natural (also no additional overhead to implement this too imo ) Also, for this you non't need to implement
|
I found that the |
You don't have to change in the You can create something like below, a passthrough mechanism in the DBExecutor which you're going to impl.
|
The documentation PR is here : |
AC1:
Given a datafile in CSV format, matching the Database table columns,
provide mechanism to load these data(rows and columns) in the that table.
Example:
and data in CSV is as below:
Note- There are no headers present in the above CSV
AC2:
Same as AC1, but with headers.
Example:
and data in CSV is as below:
AC3 :
Required for Postgres DB (v9 to v12 should be supported )
AC4:
File could be present in the local files system(eg /test/resources)
optional:
(or in a git repo ==> implement this via a separate ticket.)
AC5 :
AC6:
From @javiertuya :
This is a proposal for discussion before starting the implementation:
Where to place the code? Ans:
org.jsmart.zerocode.core.db
packageUse Apache Commons DbUtils that is a very stable and lightweight library.
This will allow to implement something that does not depend on any particular DBMS.
Add an executor (e.g.
DbSqlExecutor
) with the operation explained in the exampleas well as
EXECUTE
(orSELECT
andUPDATE
separately) to handle SQL queries with parametersTests would use H2, as it is already included as test scoped dependency.
Postgress requires a container(an example of Docker already present), this should be tested manually, or added to the CI pipeline if required.
More >>
Parametrized.java
class. : What does this mean? Please explain this or point to the PR when implemented.On the AC6 or AC5, please discuss with @javiertuya if you have any questions or suggestions.
ACRONYMS:
The text was updated successfully, but these errors were encountered: