public JsonObject formatGroupFunction(GroupFunction groupFunction) throws JsonException { if (groupFunction == null) { return null; } JsonObject groupFunctionJson = Json.createObject(); groupFunctionJson.put(SOURCE, groupFunction.getSourceId() != null ? groupFunction.getSourceId() : null); groupFunctionJson.put(COLUMN, groupFunction.getColumnId() != null ? groupFunction.getColumnId() : null); groupFunctionJson.put(FUNCTION, groupFunction.getFunction() != null ? groupFunction.getFunction().toString() : null); return groupFunctionJson; }
public GroupFunction parseGroupFunction( JsonObject groupFunctionJson ) { if (groupFunctionJson == null) { return null; } GroupFunction groupFunction = new GroupFunction(); groupFunction.setSourceId(groupFunctionJson.getString(keySet(SOURCE))); groupFunction.setColumnId(groupFunctionJson.getString(keySet(COLUMN))); groupFunction.setFunction(AggregateFunctionType.getByName(groupFunctionJson.getString(keySet(FUNCTION)))); return groupFunction; }
void onAddColumn() { if (lookupConstraints.areExtraColumnsAllowed()) { DataSetGroup op = getFirstGroupOp(); List<GroupFunction> functionList = op.getGroupFunctions(); GroupFunction last = functionList.get(functionList.size() - 1); GroupFunction clone = last.cloneInstance(); String newColumnId = lookupConstraints.buildUniqueColumnId(dataSetLookup, clone); clone.setColumnId(newColumnId); functionList.add(clone); updateColumnControls(); changeEvent.fire(new DataSetLookupChangedEvent(dataSetLookup)); } }
protected String _getTargetColumnId(GroupFunction gf) { String sourceId = gf.getSourceId(); if (sourceId != null) { _assertColumnExists(metadata, sourceId); } return gf.getColumnId() == null ? sourceId : gf.getColumnId(); } }
void onColumnSelected() { groupFunction.setSourceId(view.getSelectedColumnId()); if (!isColumnNumeric()) { groupFunction.setFunction(null); } else { groupFunction.setFunction(getSupportedFunctionTypes().get(0)); } initFunctionListBox(); changeEvent.fire(new GroupFunctionChangedEvent(groupFunction)); }
public boolean groupColumnMustBeIncluded(DataSetGroup groupOp) { if (groupOp != null) { ColumnGroup cg = groupOp.getColumnGroup(); if (cg != null) { for (GroupFunction gf : groupOp.getGroupFunctions()) { if (cg.getSourceId().equals(gf.getSourceId()) && gf.getFunction() == null) { return false; } } for (GroupFunction gf : groupOp.getGroupFunctions()) { if (!cg.getSourceId().equals(gf.getSourceId()) && gf.getFunction() == null) { return true; } } } } return false; }
assertNull(gf1.getFunction()); assertEquals(gf1.getSourceId(), OFFICE); assertEquals(gf1.getColumnId(), OFFICE); assertEquals(gf2.getFunction(), AggregateFunctionType.COUNT); assertNull(gf2.getSourceId()); assertNotNull(gf2.getColumnId()); GroupFunction extra = gf2.cloneInstance(); String extraId = lookupConstraints.buildUniqueColumnId(lookup, extra); extra.setColumnId(extraId); groupOp.getGroupFunctions().add(extra); assertNotNull(extraId); extra = gf2.cloneInstance(); extraId = lookupConstraints.buildUniqueColumnId(lookup, extra); extra.setColumnId(extraId); groupOp.getGroupFunctions().add(extra); assertNotNull(extraId);
_query.groupBy(SQLFactory.column(dbColumnId)); for (GroupFunction gf : groupOp.getGroupFunctions()) { if (!sourceId.equals(gf.getSourceId()) && gf.getFunction() == null) { postProcessing = true; if (gf.getFunction() == null && !gf.getSourceId().equalsIgnoreCase(cg.getSourceId())) { String dbGfId = _columnFromMetadata(metadata, gf.getSourceId()); _query.groupBy(SQLFactory.column(dbGfId)); AggregateFunctionType pft = pgf.getFunction(); pgf.setSourceId(_getTargetColumnId(pgf)); if (pft != null && (AggregateFunctionType.DISTINCT.equals(pft) || AggregateFunctionType.COUNT.equals(pft))) { pgf.setFunction(AggregateFunctionType.SUM);
public T expression(String expression) { DataSetOp op = getCurrentOp(); if (op == null || !(op instanceof DataSetGroup)) { throw new RuntimeException("column(...) must be called first."); } DataSetGroup gOp = (DataSetGroup) getCurrentOp(); List<GroupFunction> columns = gOp.getGroupFunctions(); if (columns.isEmpty()) { throw new RuntimeException("column(...) must be called first."); } GroupFunction lastColumn = columns.get(columns.size() - 1); return expression(lastColumn.getColumnId(), expression); }
@Test public void testColumnChanged() { DataSetLookup lookup = DATA_2D_MULTIPLE.newDataSetLookup(POPULATION_META); presenter.init(DATA_2D_MULTIPLE, lookup); GroupFunction gf = new GroupFunction("population", "population", AggregateFunctionType.SUM); presenter.onColumnFunctionChanged(new GroupFunctionChangedEvent(gf)); assertEquals(gf.getColumnId(), "population_2"); } }
String columnId = groupFunction.getColumnId(); if (columnNameMap.containsKey(columnId)) { String columnName = columnNameMap.get(columnId); groupFunction.setColumnId(columnName);
public GroupFunction cloneInstance() { GroupFunction clone = new GroupFunction(); clone.sourceId = sourceId; clone.columnId = columnId; clone.function = function; return clone; }
public DataColumn getColumnById(String id) { for (DataColumn column : columns) { if (column.getId().equalsIgnoreCase(id)) { return column; } GroupFunction gf = column.getGroupFunction(); if (gf != null && gf.getSourceId() != null && gf.getSourceId().equalsIgnoreCase(id)) { return column; } } return null; }
@Test public void testSelectColumn() { when(view.getSelectedColumnId()).thenReturn("column2"); GroupFunction groupFunction = new GroupFunction("column1", "column1", AggregateFunctionType.COUNT); presenter.init(metadata, groupFunction, null, "Title", true, true); presenter.onColumnSelected(); assertEquals(presenter.getGroupFunction().getSourceId(), "column2"); verify(changeEvent).fire(any(GroupFunctionChangedEvent.class)); }
@Test public void testSelectFunction() { when(view.getSelectedFunctionIndex()).thenReturn(1); GroupFunction groupFunction = new GroupFunction("column1", "column1", AggregateFunctionType.COUNT); presenter.init(metadata, groupFunction, null, "Title", true, true); presenter.onFunctionSelected(); List<AggregateFunctionType> supportedFunctions = presenter.getSupportedFunctionTypes(); assertEquals(presenter.getGroupFunction().getFunction(), supportedFunctions.get(1)); verify(changeEvent).fire(any(GroupFunctionChangedEvent.class)); }
public List<GroupFunction> getAggregationFunctions() { List<GroupFunction> result = new ArrayList<GroupFunction>(); for (GroupFunction groupFunction : groupFunctionList) { if (groupFunction.getFunction() != null) { result.add(groupFunction); } } return result; }
groupFunction.setFunction(null); groupOp.getGroupFunctions().remove(0); GroupFunction groupFunction = new GroupFunction(columnId, columnId, null);
void onColumnFunctionChanged(@Observes GroupFunctionChangedEvent event) { GroupFunction gf = event.getGroupFunction(); String newColumnId = lookupConstraints.buildUniqueColumnId(dataSetLookup, gf); gf.setColumnId(newColumnId); changeEvent.fire(new DataSetLookupChangedEvent(dataSetLookup)); }
@Override protected void beforeDataSetLookup() { DataSetGroup group = dataSetHandler.getCurrentDataSetLookup().getLastGroupOp(); if (group != null && (group.getAggregationFunctions().isEmpty() || group.getColumnGroup() != null || group.getGroupFunctions().size() < 2)) { group.setColumnGroup(null); GroupFunction minFunction = group.getGroupFunctions().get(0); minFunction.setFunction(AggregateFunctionType.MIN); GroupFunction maxFunction = minFunction.cloneInstance(); maxFunction.setFunction(AggregateFunctionType.MAX); group.addGroupFunction(maxFunction); } }
public DataSetGroup cloneInstance() { DataSetGroup clone = new DataSetGroup(); clone.dataSetUUID = dataSetUUID; if (columnGroup != null) clone.columnGroup = columnGroup.cloneInstance(); clone.join = join; clone.selectedIntervalList = new ArrayList(); for (Interval interval : selectedIntervalList) { clone.selectedIntervalList.add(interval.cloneInstance()); } clone.groupFunctionList = new ArrayList(); for (GroupFunction groupFunction : groupFunctionList) { clone.groupFunctionList.add(groupFunction.cloneInstance()); } return clone; }