-
Notifications
You must be signed in to change notification settings - Fork 7
Implement SQL sinks #903
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
Merged
Merged
Implement SQL sinks #903
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
a60a49a
Implemented SQLSink
jo-bao b4a04ae
New quoting
jo-bao d5f1c9f
documentations
jo-bao 31ff1c8
implementend createTable
jo-bao 542f5d4
Merge branch 'dev' into jb/#762-sql-grid-datasources
jo-bao 0f46762
spotless
jo-bao b712f17
Improve SqlUtils
jo-bao c963923
Merge branch 'dev' into jb/#762-sql-grid-datasources
jo-bao 75c57f9
Temprorary
jo-bao 4955b93
temp
jo-bao a0d8bbd
Merge branch 'dev' into jb/#762-sql-grid-datasources
jo-bao 31da1fd
Merge remote-tracking branch 'origin/dev' into jb/#762-sql-grid-datas…
jo-bao 4243e57
Merge branch 'dev' into jb/#762-sql-grid-datasources
jo-bao d85e234
fixing tests
15d97cc
replace UniqueEntity
jo-bao d77e478
Main Method
jo-bao a079b8c
Merge branch 'dev' into jb/#762-sql-grid-datasources
jo-bao 6667c3d
Code Cleaning
jo-bao 6bb4abe
Code Cleaning
jo-bao f62a10d
SQL Caps
jo-bao 5d0a594
Fixing sonarqube
4da951e
optimize tests
97f2a4f
Merge branch 'dev' into jb/#762-sql-grid-datasources
t-ober 16f65e8
Merge branch 'dev' into jb/#762-sql-grid-datasources
62564e2
changes after review
jo-bao 802d4d2
fixing Sonarqube
jo-bao 0072c43
Merge branch 'dev' into jb/#762-sql-grid-datasources
t-ober 8e7ee6d
Merge remote-tracking branch 'origin/dev' into jb/#762-sql-grid-datas…
jo-bao 07eed44
simplify persist joint grid
jo-bao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* © 2023. TU Dortmund University, | ||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
* Research group Distribution grid planning and operation | ||
*/ | ||
package edu.ie3.datamodel.io; | ||
|
||
import static edu.ie3.datamodel.io.SqlUtils.quote; | ||
|
||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
|
||
/** Class for identification of entities and results from grids in SQL databases. */ | ||
public record DbGridMetadata(String gridName, UUID uuid) { | ||
|
||
public static final String GRID_TABLE = "grids"; | ||
public static final String GRID_NAME = "grid_name"; | ||
public static final String GRID_UUID = "grid_uuid"; | ||
|
||
public String toString() { | ||
return GRID_NAME + "=" + gridName + ", " + GRID_UUID + "=" + uuid.toString(); | ||
} | ||
|
||
/** @return Stream with grid uuid */ | ||
public Stream<String> getStreamForQuery() { | ||
return Stream.of(quote(uuid.toString(), "'")); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* © 2023. TU Dortmund University, | ||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
* Research group Distribution grid planning and operation | ||
*/ | ||
package edu.ie3.datamodel.io; | ||
|
||
import java.util.Objects; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class SqlUtils { | ||
|
||
protected static final Logger log = LoggerFactory.getLogger(SqlUtils.class); | ||
private static final String endQueryCreateTable = | ||
")\n \t WITHOUT OIDS\n \t TABLESPACE pg_default;"; | ||
|
||
private SqlUtils() { | ||
throw new IllegalStateException("Utility classes cannot be instantiated"); | ||
} | ||
|
||
private static String beginQueryCreateTable(String schemaName, String tableName) { | ||
return "CREATE TABLE " + schemaName + "." + tableName + "\n(\n"; | ||
} | ||
|
||
/** @return query to create a SQL table for a grid */ | ||
public static String queryCreateGridTable(String schemaName) { | ||
return beginQueryCreateTable(schemaName, DbGridMetadata.GRID_TABLE) | ||
+ "\tuuid uuid PRIMARY KEY,\n\tname TEXT NOT NULL\n" | ||
+ endQueryCreateTable; | ||
} | ||
|
||
/** | ||
* To avoid data type conflicts while insertion into a SQL table all columns should be quoted. | ||
* | ||
* @return input with quoteSymbol | ||
*/ | ||
public static String quote(String input, String quoteSymbol) { | ||
if (Objects.equals(input, "") || Objects.equals(input, "null")) { | ||
return "NULL"; | ||
} else { | ||
return input.matches("^\".*\"$") ? input : quoteSymbol + input + quoteSymbol; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.