-
Notifications
You must be signed in to change notification settings - Fork 8
Feature/sql command #293
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
base: develop
Are you sure you want to change the base?
Feature/sql command #293
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| ### Command: sql | ||
| The sql commands allows the user to write SQL queries directly to the connected Database of his choice. | ||
| rosetta [-c, --config CONFIG_FILE] sql [-h, --help] [-s, --source CONNECTION_NAME] [-q, --sql "Write SQL for you Schema"] [--output "Output DIRECTORY or FILE"] | ||
|
Comment on lines
+2
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix grammar: "you" should be "your". Based on static analysis hints, there are grammar issues on lines 3 and 10 where "you" should be "your". Also, the command synopsis shows 🔎 Proposed fix-The sql commands allows the user to write SQL queries directly to the connected Database of his choice.
- rosetta [-c, --config CONFIG_FILE] sql [-h, --help] [-s, --source CONNECTION_NAME] [-q, --sql "Write SQL for you Schema"] [--output "Output DIRECTORY or FILE"]
+The sql command allows the user to write SQL queries directly to the connected database of their choice.
+ rosetta [-c, --config CONFIG_FILE] sql [-h, --help] [-s, --source CONNECTION_NAME] [-q, --query "Your SQL Query"] [-l, --limit ROW_LIMIT] [--no-limit] [--output "Output DIRECTORY or FILE"]
🧰 Tools🪛 LanguageTool[grammar] ~3-~3: Ensure spelling is correct (QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1) 🪛 markdownlint-cli2 (0.18.1)2-2: Heading levels should only increment by one level at a time (MD001, heading-increment) 🤖 Prompt for AI Agents |
||
|
|
||
| Parameter | Description | ||
| --- | --- | ||
| -h, --help | Show the help message and exit. | ||
| -c, --config CONFIG_FILE | YAML config file. If none is supplied it will use main.conf in the current directory if it exists. | ||
| -s, --source CONNECTION_NAME | The source connection is used to specify which models and connection to use. | ||
| -q --sql "SQL Query Code" | specify the query you want to run in you connected DB. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix grammar: "you" should be "your". 🔎 Proposed fix--q --sql "SQL Query Code" | specify the query you want to run in you connected DB.
+-q, --query "SQL Query Code" | Specify the query you want to run in your connected DB.🧰 Tools🪛 LanguageTool[grammar] ~10-~10: Ensure spelling is correct (QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1) 🤖 Prompt for AI Agents |
||
| -l --limit Response Row limit (Optional) | Limits the number of rows in the generated CSV file. If not specified, the default limit is set to 200 rows. | ||
| --no-limit (Optional) | Specifies that there should be no limit on the number of rows in the generated CSV file. | ||
|
|
||
|
|
||
|
|
||
| ***Example*** (Query) | ||
| ``` | ||
| rosetta sql -s mysql -q "select * from basic_library.authors;" | ||
| ``` | ||
| ***CSV Output Example*** | ||
| ```CSV | ||
| surname,name,authorid | ||
| Howells,William Dean,1 | ||
| Brown,Frederic,2 | ||
| London,Jack,3 | ||
| Blaisdell,Albert,4 | ||
| Butler,Ellis,5 | ||
| Machen,Arthur,6 | ||
| Lucretius,Titus,7 | ||
| Tagore,Rabindranath,8 | ||
| Asimov,Isaac,9 | ||
| Dickens,Charles,10 | ||
| Emerson,Ralph Waldo,11 | ||
| Canfield,Dorothy,12 | ||
| Boccaccio,Givoanni,13 | ||
| Orwell,George,14 | ||
| Ovid,Publius,15 | ||
| Stevenson,Robert Louis,16 | ||
| Woolf,Virginia,17 | ||
| Eliot,George,18 | ||
| Edwards,Amelia B.,19 | ||
| Dostoevsky,Fyodor,20 | ||
| Dickinson,Emily,21 | ||
| Ferber,Edna,22 | ||
|
|
||
| ``` | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,46 @@ | ||||||||||||||||
| package queryhelper.service; | ||||||||||||||||
|
|
||||||||||||||||
| import com.adaptivescale.rosetta.common.models.input.Connection; | ||||||||||||||||
| import queryhelper.pojo.GenericResponse; | ||||||||||||||||
| import queryhelper.pojo.QueryDataResponse; | ||||||||||||||||
|
|
||||||||||||||||
| import java.nio.file.Path; | ||||||||||||||||
| import java.util.List; | ||||||||||||||||
| import java.util.Map; | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| import static queryhelper.utils.FileUtils.createCSVFile; | ||||||||||||||||
| import static queryhelper.utils.FileUtils.generateTablePreview; | ||||||||||||||||
| import static queryhelper.utils.QueryUtils.executeQueryAndGetRecords; | ||||||||||||||||
|
|
||||||||||||||||
| public class QueryService { | ||||||||||||||||
|
|
||||||||||||||||
| public static GenericResponse executeQuery(String query, Connection source, Integer showRowLimit, Path dataDirectory, Path outputFileName) { | ||||||||||||||||
|
|
||||||||||||||||
| GenericResponse response = new GenericResponse(); | ||||||||||||||||
| QueryDataResponse data = new QueryDataResponse(); | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| List<Map<String, Object>> records = executeQueryAndGetRecords(query, source, showRowLimit); | ||||||||||||||||
| data.setRecords(records); | ||||||||||||||||
|
|
||||||||||||||||
| response.setData(data); | ||||||||||||||||
| response.setStatusCode(200); | ||||||||||||||||
|
|
||||||||||||||||
| String csvFile = createCSVFile(data, query, dataDirectory, outputFileName); | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SQL query as filename may contain invalid characters. Using the raw SQL query as the CSV filename base can result in invalid filenames. SQL queries often contain characters like 🔎 Proposed fix - sanitize the filename- String csvFile = createCSVFile(data, query, dataDirectory, outputFileName);
+ // Sanitize query for use as filename - keep only alphanumeric chars and limit length
+ String sanitizedQuery = query.replaceAll("[^a-zA-Z0-9]", "_").replaceAll("_+", "_");
+ if (sanitizedQuery.length() > 50) {
+ sanitizedQuery = sanitizedQuery.substring(0, 50);
+ }
+ String csvFile = createCSVFile(data, sanitizedQuery, dataDirectory, outputFileName);📝 Committable suggestion
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| String table = generateTablePreview(csvFile, 15); | ||||||||||||||||
|
|
||||||||||||||||
| response.setMessage( | ||||||||||||||||
| query + "\n" + | ||||||||||||||||
| "Your response is saved to a CSV file named '" + csvFile + "'!" + "\n" + | ||||||||||||||||
| "Table Output:" + "\n" + | ||||||||||||||||
| table + | ||||||||||||||||
| "..." + "\n" + | ||||||||||||||||
| "Total rows: " + data.getRecords().size() | ||||||||||||||||
| ); | ||||||||||||||||
|
|
||||||||||||||||
| return response; | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: rosettadb/rosetta
Length of output: 26183
🏁 Script executed:
rg -n "DATABASE" cli/src/test/java/integration/ --type=java -C 2Repository: rosettadb/rosetta
Length of output: 6599
🏁 Script executed:
rg -n "withDatabaseName" cli/src/test/java/integration/ --type=javaRepository: rosettadb/rosetta
Length of output: 437
Remove unused DATABASE constant or add
.withDatabaseName(DATABASE)to container initialization.The
DATABASEconstant defined on line 41 is never used. Other integration tests (MySQL, DB2, Oracle) properly configure their database names with.withDatabaseName(DATABASE), butSqlserverIntegrationTestis missing this configuration. Either add.withDatabaseName(DATABASE)to theMSSQLServerContainerinitialization on line 172, or remove the unused constant.🤖 Prompt for AI Agents