Skip to content

Commit

Permalink
refactor: Split statements to separate method [DHIS2-16705] (#19446)
Browse files Browse the repository at this point in the history
  • Loading branch information
larshelge authored Dec 11, 2024
1 parent 2cc2920 commit 1140322
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,9 @@ protected void populateTableInternal(AnalyticsTablePartition partition, String f
List<AnalyticsTableColumn> columns = partition.getMasterTable().getAnalyticsTableColumns();

String sql = "insert into " + tableName + " (";

sql += toCommaSeparated(columns, col -> quote(col.getName()));

sql += ") select ";

sql += toCommaSeparated(columns, AnalyticsTableColumn::getSelectExpression);

sql += " " + fromClause;

invokeTimeAndLog(sql, "Populating table: '{}'", tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,7 @@ private List<AnalyticsTableColumn> getColumnForDataElement(
sqlBuilder.jsonExtractNested("eventdatavalues", dataElement.getUid(), "value");
String columnExpression = getColumnExpression(dataElement.getValueType(), jsonExpression);
String dataFilterClause = getDataFilterClause(dataElement);
String selectExpression =
String.format("%s as %s", columnExpression, quote(dataElement.getUid()));
String selectExpression = getSelectExpression(dataElement, columnExpression);
Skip skipIndex = skipIndex(dataElement.getValueType(), dataElement.hasOptionSet());

if (withLegendSet) {
Expand All @@ -516,6 +515,17 @@ private List<AnalyticsTableColumn> getColumnForDataElement(
return columns;
}

/**
* Returns a select expression.
*
* @param dataElement the {@link DataElement}.
* @param columnExpression the column expression.
* @return a select expression.
*/
private String getSelectExpression(DataElement dataElement, String columnExpression) {
return String.format("%s as %s", columnExpression, quote(dataElement.getUid()));
}

/**
* Returns a list of columns.
*
Expand Down

0 comments on commit 1140322

Please sign in to comment.