|
25 | 25 | import java.nio.file.Paths; |
26 | 26 | import java.nio.file.SimpleFileVisitor; |
27 | 27 | import java.nio.file.attribute.BasicFileAttributes; |
28 | | -import java.util.ArrayList; |
29 | | -import java.util.Arrays; |
30 | | -import java.util.HashMap; |
31 | | -import java.util.Iterator; |
32 | | -import java.util.List; |
33 | | -import java.util.Map; |
34 | | -import java.util.Set; |
| 28 | +import java.util.*; |
35 | 29 | import java.util.regex.Matcher; |
36 | 30 | import java.util.regex.Pattern; |
37 | 31 |
|
@@ -174,19 +168,19 @@ protected Integer[] getIdsAsIntegers(String ids) { |
174 | 168 | public String getDataStore(String label, String parameters, Map<String, Object> drivers, String selections, |
175 | 169 | String likeSelections, int maxRowCount, String aggregations, String summaryRow, int offset, int fetchSize, |
176 | 170 | Boolean isNearRealtime, Set<String> indexes, String widgetName, boolean useGroupBy) { |
177 | | - return getDataStore(label, parameters, drivers, selections, likeSelections, maxRowCount, aggregations, |
| 171 | + return getDataStore(label, parameters, drivers, selections, likeSelections, null, maxRowCount, aggregations, |
178 | 172 | summaryRow, offset, fetchSize, isNearRealtime, null, indexes, widgetName, useGroupBy); |
179 | 173 | } |
180 | 174 |
|
181 | 175 | public String getDataStore(String label, String parameters, Map<String, Object> drivers, String selections, |
182 | 176 | String likeSelections, int maxRowCount, String aggregations, String summaryRow, int offset, int fetchSize, |
183 | 177 | Set<String> indexes, String widgetName, boolean useGroupBy) { |
184 | | - return getDataStore(label, parameters, drivers, selections, likeSelections, maxRowCount, aggregations, |
| 178 | + return getDataStore(label, parameters, drivers, selections, likeSelections, null, maxRowCount, aggregations, |
185 | 179 | summaryRow, offset, fetchSize, null, null, indexes, widgetName, useGroupBy); |
186 | 180 | } |
187 | 181 |
|
188 | 182 | public String getDataStore(String label, String parameters, Map<String, Object> drivers, String selections, |
189 | | - String likeSelections, int maxRowCount, String aggregations, String summaryRow, int offset, int fetchSize, |
| 183 | + String likeSelections, String drilldown, int maxRowCount, String aggregations, String summaryRow, int offset, int fetchSize, |
190 | 184 | Boolean isNearRealtime, String options, Set<String> indexes, String widgetName, boolean useGroupBy) { |
191 | 185 | LOGGER.debug("IN"); |
192 | 186 | DatasetManagementAPI datasetManagementAPI = getDatasetManagementAPI(); |
@@ -290,12 +284,22 @@ public String getDataStore(String label, String parameters, Map<String, Object> |
290 | 284 | } |
291 | 285 | } |
292 | 286 |
|
| 287 | + List<Filter> drilldownFilters = new ArrayList<>(0); |
| 288 | + if (drilldown != null && !drilldown.equals("")) { |
| 289 | + JSONObject drilldownObject = new JSONObject(drilldown); |
| 290 | + if (drilldownObject.names() != null) { |
| 291 | + drilldownFilters.addAll(getDrilldownFilters(label, drilldownObject, columnAliasToName)); |
| 292 | + } |
| 293 | + } |
| 294 | + |
293 | 295 | Monitor timingMinMax = MonitorFactory.start("Knowage.AbstractDataSetResource.getDataStore:calculateMinMax"); |
294 | 296 | Map<String, String> parametersMap = DataSetUtilities.getParametersMap(parameters); |
295 | 297 | filters = datasetManagementAPI.calculateMinMaxFilters(dataSet, isNearRealtime, parametersMap, filters, |
296 | 298 | likeFilters, indexes); |
297 | 299 | timingMinMax.stop(); |
298 | 300 |
|
| 301 | + filters.addAll(drilldownFilters); |
| 302 | + |
299 | 303 | Filter where = datasetManagementAPI.getWhereFilter(filters, likeFilters); |
300 | 304 |
|
301 | 305 | timing.stop(); |
@@ -346,7 +350,8 @@ public String getDataStore(String label, String parameters, Map<String, Object> |
346 | 350 | } |
347 | 351 | } |
348 | 352 |
|
349 | | - public String getDataStoreAI(String label, String parameters, Map<String, Object> drivers, String selections, |
| 353 | + |
| 354 | + public String getDataStoreAI(String label, String parameters, Map<String, Object> drivers, String selections, |
350 | 355 | String likeSelections, Integer maxRowCount, String aggregations, String summaryRow, int offset, int fetchSize, Integer maxRows, |
351 | 356 | Boolean isNearRealtime, String options, Set<String> indexes) { |
352 | 357 | LOGGER.debug("IN"); |
@@ -1126,6 +1131,47 @@ protected List<SimpleFilter> getLikeFilters(String datasetLabel, JSONObject like |
1126 | 1131 | return likeFilters; |
1127 | 1132 | } |
1128 | 1133 |
|
| 1134 | + |
| 1135 | + private List<Filter> getDrilldownFilters(String datasetLabel, JSONObject drilldownObject, Map<String, String> columnAliasToName) throws JSONException { |
| 1136 | + |
| 1137 | + List<Filter> drilldownFilters = new ArrayList<>(0); |
| 1138 | + |
| 1139 | + if (drilldownObject.has(datasetLabel)) { |
| 1140 | + IDataSet dataSet = getDataSetDAO().loadDataSetByLabel(datasetLabel); |
| 1141 | + boolean isAnEmptySelection = false; |
| 1142 | + |
| 1143 | + JSONObject drilldownObjectJSONObject = drilldownObject.getJSONObject(datasetLabel); |
| 1144 | + Iterator<String> it = drilldownObjectJSONObject.keys(); |
| 1145 | + while (it.hasNext()) { |
| 1146 | + String columns = it.next(); |
| 1147 | + String value = drilldownObjectJSONObject.getString(columns); |
| 1148 | + if (value == null || value.isEmpty()) { |
| 1149 | + isAnEmptySelection = true; |
| 1150 | + break; |
| 1151 | + } |
| 1152 | + |
| 1153 | + List<String> columnsList = getColumnList(columns, dataSet, columnAliasToName); |
| 1154 | + List<Projection> projections = new ArrayList<>(columnsList.size()); |
| 1155 | + for (String columnName : columnsList) { |
| 1156 | + projections.add(new Projection(dataSet, columnName)); |
| 1157 | + } |
| 1158 | + |
| 1159 | + for (Projection projection : projections) { |
| 1160 | + SimpleFilter filter = new InFilter(projection, value); |
| 1161 | + drilldownFilters.add(filter); |
| 1162 | + } |
| 1163 | + } |
| 1164 | + |
| 1165 | + if (isAnEmptySelection) { |
| 1166 | + drilldownFilters.clear(); |
| 1167 | + drilldownFilters.add(new UnsatisfiedFilter()); |
| 1168 | + } |
| 1169 | + } |
| 1170 | + |
| 1171 | + return drilldownFilters; |
| 1172 | + } |
| 1173 | + |
| 1174 | + |
1129 | 1175 | protected List<String> getColumnList(String columns, IDataSet dataSet, |
1130 | 1176 | Map<String, String> columnAliasToColumnName) { |
1131 | 1177 | List<String> columnList = new ArrayList<>(Arrays.asList(columns.trim().replaceAll("\\s+", " ").split("\\s?,\\s?"))); |
|
0 commit comments