List of usage examples for java.util LinkedHashMap put
V put(K key, V value);
From source file:eu.itesla_project.modules.histo.IIDM2DB.java
public static CimValuesMap extractCimValues(Network n, Config config) { CimValuesMap valuesMap = new CimValuesMap(); for (Substation ss : n.getSubstations()) { if (config.getCountryFilter() != null && !config.getCountryFilter().contains(ss.getCountry())) { continue; }// w w w . ja v a2 s . com for (VoltageLevel vl : ss.getVoltageLevels()) { if (vl.getNominalV() < config.getMinBaseVoltageFilter()) { continue; } String horizon = n.getForecastDistance() > 0 ? "DACF" : "SN"; // for backward compatibility final LinkedHashMap<HistoDbAttributeId, Object> valueMap = valuesMap .getValueMap(new HorizonKey(n.getForecastDistance(), horizon)); if (config.getCimName() != null && !valueMap.containsKey(HistoDbMetaAttributeId.cimName)) valueMap.put(HistoDbMetaAttributeId.cimName, config.getCimName()); if (config.isExtractTemporalFields()) { if (!valueMap.containsKey(HistoDbMetaAttributeId.datetime)) valueMap.put(HistoDbMetaAttributeId.datetime, n.getCaseDate().toDate()); if (!valueMap.containsKey(HistoDbMetaAttributeId.daytime)) valueMap.put(HistoDbMetaAttributeId.daytime, n.getCaseDate().getMillisOfDay()); if (!valueMap.containsKey(HistoDbMetaAttributeId.month)) valueMap.put(HistoDbMetaAttributeId.month, n.getCaseDate().getMonthOfYear()); if (!valueMap.containsKey(HistoDbMetaAttributeId.forecastTime)) valueMap.put(HistoDbMetaAttributeId.forecastTime, n.getForecastDistance()); if (!valueMap.containsKey(HistoDbMetaAttributeId.horizon)) valueMap.put(HistoDbMetaAttributeId.horizon, horizon); } vl.visitEquipments(new AbstractTopologyVisitor() { private void visitInjection(SingleTerminalConnectable inj) { visitInjection(inj, new TerminalContext()); } private void visitInjection(SingleTerminalConnectable inj, TerminalContext context) { Terminal t = inj.getTerminal(); context.update(t); if (config.isReplaceMissingValues()) { if (Float.isNaN(context.p)) { context.p = 0f; } if (Float.isNaN(context.q)) { context.q = 0f; } if (Float.isNaN(context.v)) { // use connectable bus voltage, better than nothing... context.v = t.getBusBreakerView().getConnectableBus().getV(); } if (Float.isNaN(context.v)) { context.v = 0f; // TODO is there a better value? } if (Float.isNaN(context.i)) { context.i = 0f; } } valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.P), context.p); valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.Q), context.q); valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.V), context.v); valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.I), context.i); } private void visitBranch(TwoTerminalsConnectable branch, TwoTerminalsConnectable.Side side, float r, float x, float g1, float b1, float g2, float b2, float ratio) { Terminal t = side == TwoTerminalsConnectable.Side.ONE ? branch.getTerminal1() : branch.getTerminal2(); TerminalContext context = TerminalContext.create(t); if (config.isReplaceMissingValues()) { if (Float.isNaN(context.p)) { context.p = 0f; } if (Float.isNaN(context.q)) { context.q = 0f; } if (Float.isNaN(context.v)) { Terminal otherT = t == branch.getTerminal1() ? branch.getTerminal2() : branch.getTerminal1(); Bus otherBus = otherT.getBusView().getBus(); if (otherBus != null && !Float.isNaN(otherBus.getV())) { // compute the voltage from the other side physical values // TODO approx we do not consider voltage drop due to branch impedance if (t == branch.getTerminal1()) { // we are on side 1 disconnected and side 2 is connected context.v = otherBus.getV() / ratio; } else if (t == branch.getTerminal2()) { // we are on side 2 disconnected and side 1 is connected context.v = otherBus.getV() * ratio; } else { throw new AssertionError(); } } else { // use connectable bus voltage, better than nothing... context.v = t.getBusBreakerView().getConnectableBus().getV(); } } if (Float.isNaN(context.v)) { context.v = 0; // TODO is there a better value? } if (Float.isNaN(context.i)) { context.i = 0; } } valueMap.put(new HistoDbNetworkAttributeId(branch.getId(), t.getVoltageLevel().getId(), HistoDbAttr.P), context.p); valueMap.put(new HistoDbNetworkAttributeId(branch.getId(), t.getVoltageLevel().getId(), HistoDbAttr.Q), context.q); valueMap.put(new HistoDbNetworkAttributeId(branch.getId(), t.getVoltageLevel().getId(), HistoDbAttr.V), context.v); valueMap.put(new HistoDbNetworkAttributeId(branch.getId(), t.getVoltageLevel().getId(), HistoDbAttr.I), context.i); } @Override public void visitGenerator(Generator g) { TerminalContext context = new TerminalContext(); visitInjection(g, context); // reactive limit float qmax = g.getReactiveLimits().getMaxQ(context.p); valueMap.put(new HistoDbNetworkAttributeId(g.getId(), HistoDbAttr.QR), Math.abs(qmax - context.q)); } @Override public void visitLoad(Load l) { if (l.getLoadType() != LoadType.FICTITIOUS) { visitInjection(l); } } @Override public void visitShuntCompensator(ShuntCompensator sc) { visitInjection(sc); } @Override public void visitDanglingLine(DanglingLine dl) { visitInjection(dl); valueMap.put(new HistoDbNetworkAttributeId(dl.getId(), HistoDbAttr.P0), dl.getP0()); valueMap.put(new HistoDbNetworkAttributeId(dl.getId(), HistoDbAttr.Q0), dl.getQ0()); } @Override public void visitLine(Line l, Line.Side side) { visitBranch(l, side, l.getR(), l.getX(), l.getG1(), l.getB1(), l.getG2(), l.getB2(), 1); } @Override public void visitTwoWindingsTransformer(TwoWindingsTransformer twt, TwoWindingsTransformer.Side side) { visitBranch(twt, side, twt.getR(), twt.getX(), twt.getG(), twt.getB(), 0, 0, SV.getRatio(twt)); } @Override public void visitThreeWindingsTransformer(ThreeWindingsTransformer twt, ThreeWindingsTransformer.Side side) { Terminal t; switch (side) { case ONE: t = twt.getLeg1().getTerminal(); break; case TWO: t = twt.getLeg2().getTerminal(); break; case THREE: t = twt.getLeg3().getTerminal(); break; default: throw new AssertionError(); } TerminalContext context = TerminalContext.create(t); if (config.isReplaceMissingValues()) { if (Float.isNaN(context.p)) { context.p = 0f; } if (Float.isNaN(context.q)) { context.q = 0f; } if (Float.isNaN(context.v)) { context.v = 0; // TODO is possible to find a better replacement value? } if (Float.isNaN(context.i)) { context.i = 0f; } } valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), t.getVoltageLevel().getId(), HistoDbAttr.V), context.v); valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), t.getVoltageLevel().getId(), HistoDbAttr.I), context.i); valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), t.getVoltageLevel().getId(), HistoDbAttr.P), context.p); valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), t.getVoltageLevel().getId(), HistoDbAttr.Q), context.q); } }); // taps for (TwoWindingsTransformer twt : ss.getTwoWindingsTransformers()) { if (twt.getPhaseTapChanger() != null) { valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), HistoDbAttr.PTC), twt.getPhaseTapChanger().getTapPosition()); } if (twt.getRatioTapChanger() != null) { valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), HistoDbAttr.RTC), twt.getRatioTapChanger().getTapPosition()); } } for (ThreeWindingsTransformer twt : ss.getThreeWindingsTransformers()) { valueMap.put( new HistoDbNetworkAttributeId(twt.getId(), twt.getLeg2().getTerminal().getVoltageLevel().getId(), HistoDbAttr.RTC), twt.getLeg2().getRatioTapChanger().getTapPosition()); valueMap.put( new HistoDbNetworkAttributeId(twt.getId(), twt.getLeg3().getTerminal().getVoltageLevel().getId(), HistoDbAttr.RTC), twt.getLeg3().getRatioTapChanger().getTapPosition()); } /** * Extract topologies and mean tension */ try { JSONArray toposArray = toTopoSet(vl); String jsonRep = toposArray.toString(); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.TOPO), jsonRep); String base64hash = computeTopoHash(jsonRep); valuesMap.addTopology(vl.getId(), base64hash, toposArray); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.TOPOHASH), base64hash); } catch (JSONException e) { throw new RuntimeException("Failed to gather topologies", e); } float pgen = 0; float qgen = 0; float pload = 0; float qload = 0; float qshunt = 0; for (Generator g : vl.getGenerators()) { Terminal t = g.getTerminal(); if (t.getBusView().getBus() != null) { if (!Float.isNaN(t.getP())) { pgen += t.getP(); } if (!Float.isNaN(t.getQ())) { qgen += t.getQ(); } } } for (Load l : vl.getLoads()) { Terminal t = l.getTerminal(); if (t.getBusView().getBus() != null) { if (!Float.isNaN(t.getP())) { pload += t.getP(); } if (!Float.isNaN(t.getQ())) { qload += t.getQ(); } } } for (ShuntCompensator s : vl.getShunts()) { Terminal t = s.getTerminal(); if (t.getBusView().getBus() != null) { if (!Float.isNaN(t.getQ())) { qshunt += t.getQ(); } } } float vSum = 0; int validBusCount = 0; int busCount = 0; float vMin = Float.NaN; float vMax = Float.NaN; for (Bus b : vl.getBusView().getBuses()) { if (!Float.isNaN(b.getV())) { vSum += b.getV(); validBusCount++; vMin = Float.isNaN(vMin) ? b.getV() : Math.min(vMin, b.getV()); vMax = Float.isNaN(vMax) ? b.getV() : Math.max(vMax, b.getV()); } busCount++; } float meanV = Float.NaN; if (validBusCount > 0) { meanV = vSum / validBusCount; } if (config.isReplaceMissingValues()) { if (Float.isNaN(meanV)) { meanV = 0; // TODO is there a better value? } if (Float.isNaN(vMin)) { vMin = 0; // TODO is there a better value? } if (Float.isNaN(vMax)) { vMax = 0; // TODO is there a better value? } } valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.PGEN), pgen); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.QGEN), qgen); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.PLOAD), pload); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.QLOAD), qload); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.QSHUNT), qshunt); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.V), meanV); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.VMIN), vMin); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.VMAX), vMax); valueMap.put(new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.BC), busCount); } } return valuesMap; }
From source file:com.k42b3.quantum.worker.HttpWorkerAbstract.java
public Map<String, String> getParameters() { LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>(); parameters.put("url", "Url"); return parameters; }
From source file:net.jmhertlein.mcanalytics.api.request.UniqueLoginsPerDayRequest.java
@Override public Map<LocalDate, Integer> processResponse(JSONObject response) { JSONObject counts = response.getJSONObject("logins"); LinkedHashMap<LocalDate, Integer> ret = new LinkedHashMap<>(); for (String s : counts.keySet()) { ret.put(LocalDate.parse(s), counts.getInt(s)); }/*ww w . j ava 2 s.com*/ return ret; }
From source file:com.yyl.common.utils.excel.ExcelTools.java
/** * ?ApachePOIAPI??Excel???List?ListJson??LinkedExcel??? * @param inputStream ?urlurlinput?/* w ww .jav a2 s . co m*/ * @param FileName ???????excel * @param headers list,String-->Arrays.asList(); * @return Map HashMapExcelsheet?sheetkeysheet?json?value * @throws IOException */ public static Map<String, String> excel2json(InputStream inputStream, String fileName, List<String> headers) throws IOException { System.out.println("excel2json...."); // map Map<String, String> excelMap = new LinkedHashMap<>(); // Excel??Excel CellStyle cellStyle; // ?Excel? Workbook wb; // 2007??Workbook?CellStyle if (fileName.endsWith("xlsx")) { System.out.println("2007? xlsx"); wb = new XSSFWorkbook(inputStream); XSSFDataFormat dataFormat = (XSSFDataFormat) wb.createDataFormat(); cellStyle = wb.createCellStyle(); // Excel? cellStyle.setDataFormat(dataFormat.getFormat("@")); } else { System.out.println("2007 xls"); POIFSFileSystem fs = new POIFSFileSystem(inputStream); wb = new HSSFWorkbook(fs); HSSFDataFormat dataFormat = (HSSFDataFormat) wb.createDataFormat(); cellStyle = wb.createCellStyle(); // Excel? cellStyle.setDataFormat(dataFormat.getFormat("@")); } // sheet int sheetsCounts = wb.getNumberOfSheets(); // ???sheet for (int i = 0; i < sheetsCounts; i++) { Sheet sheet = wb.getSheetAt(i); System.out.println("" + i + "sheet:" + sheet.toString()); // sheetList List list = new LinkedList(); // ?key Row fisrtRow = sheet.getRow(0); // sheet if (null == fisrtRow) { continue; } // int curCellNum = fisrtRow.getLastCellNum(); System.out.println("" + curCellNum); // ??? int rowNum = sheet.getLastRowNum(); System.out.println(" " + rowNum + " "); for (int j = 1; j < rowNum; j++) { // ?Map LinkedHashMap rowMap = new LinkedHashMap(); // ?? Row row = sheet.getRow(j); int cellNum = row.getLastCellNum(); // ??? for (int k = 0; k < cellNum; k++) { Cell cell = row.getCell(k); // ??? rowMap.put(headers.get(k), getCellValue(cell)); } // ??List list.add(rowMap); } // sheet??keyListjson?Value excelMap.put(sheet.getSheetName(), JacksonUtil.bean2Json(list)); } System.out.println("excel2json?...."); return excelMap; }
From source file:org.apache.commons.scxml2.io.ContentParserTest.java
@Test public void testParseJson() throws Exception { ObjectMapper jsonObjectMapper = new ObjectMapper(); jsonObjectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); jsonObjectMapper.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS, true); // not by default configured, but much easier for unit-testing Java embedded JSON Strings jsonObjectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); ContentParser contentParser = new ContentParser(jsonObjectMapper); String jsonObjectString = "{ /*comment*/ 'string' : 'foobar', 'int' : 1, 'boolean' : false, 'null' : null }"; LinkedHashMap<String, Object> jsonObject = new LinkedHashMap<>(); jsonObject.put("string", "foobar"); jsonObject.put("int", new Integer(1)); jsonObject.put("boolean", Boolean.FALSE); jsonObject.put("null", null); Assert.assertEquals(jsonObject, contentParser.parseJson(jsonObjectString)); String jsonArrayString = "[" + jsonObjectString + "," + "# yaml comment\n" + jsonObjectString + "]"; ArrayList<Object> jsonArray = new ArrayList<>(2); jsonArray.add(jsonObject);// ww w .j a v a 2s. c om jsonArray.add(jsonObject); Assert.assertEquals(jsonArray, contentParser.parseJson(jsonArrayString)); }
From source file:org.kitodo.data.index.elasticsearch.type.ProcessType.java
@SuppressWarnings("unchecked") @Override/* w w w .j a v a2 s. c om*/ public HttpEntity createDocument(Process process) { LinkedHashMap<String, String> orderedProcessMap = new LinkedHashMap<>(); orderedProcessMap.put("name", process.getTitle()); orderedProcessMap.put("outputName", process.getOutputName()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String creationDate = process.getCreationDate() != null ? dateFormat.format(process.getCreationDate()) : null; orderedProcessMap.put("creationDate", creationDate); orderedProcessMap.put("wikiField", process.getWikiField()); String project = process.getProject() != null ? process.getProject().getId().toString() : "null"; orderedProcessMap.put("project", project); String ruleset = process.getRuleset() != null ? process.getRuleset().getId().toString() : "null"; orderedProcessMap.put("ruleset", ruleset); String ldapGroup = process.getDocket() != null ? process.getDocket().getId().toString() : "null"; orderedProcessMap.put("ldapGroup", ldapGroup); JSONObject processObject = new JSONObject(orderedProcessMap); JSONArray properties = new JSONArray(); List<ProcessProperty> processProperties = process.getProperties(); for (ProcessProperty property : processProperties) { JSONObject propertyObject = new JSONObject(); propertyObject.put("title", property.getTitle()); propertyObject.put("value", property.getValue()); properties.add(propertyObject); } processObject.put("properties", properties); return new NStringEntity(processObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:org.kitodo.data.index.elasticsearch.type.UserType.java
@SuppressWarnings("unchecked") @Override//from w ww. ja v a 2 s. c om public HttpEntity createDocument(User user) { LinkedHashMap<String, String> orderedUserMap = new LinkedHashMap<>(); orderedUserMap.put("name", user.getName()); orderedUserMap.put("surname", user.getSurname()); orderedUserMap.put("login", user.getLogin()); orderedUserMap.put("ldapLogin", user.getLdapLogin()); orderedUserMap.put("active", String.valueOf(user.isActive())); orderedUserMap.put("location", user.getLocation()); orderedUserMap.put("metadataLanguage", user.getMetadataLanguage()); String ldapGroup = user.getLdapGroup() != null ? user.getLdapGroup().getId().toString() : "null"; orderedUserMap.put("ldapGroup", ldapGroup); JSONObject userObject = new JSONObject(orderedUserMap); JSONArray userGroups = new JSONArray(); List<UserGroup> userUserGroups = user.getUserGroups(); for (UserGroup userGroup : userUserGroups) { JSONObject userGroupObject = new JSONObject(); userGroupObject.put("id", userGroup.getId().toString()); userGroups.add(userGroupObject); } userObject.put("userGroups", userGroups); JSONArray properties = new JSONArray(); List<UserProperty> userProperties = user.getProperties(); for (UserProperty property : userProperties) { JSONObject propertyObject = new JSONObject(); propertyObject.put("title", property.getTitle()); propertyObject.put("value", property.getValue()); properties.add(propertyObject); } userObject.put("properties", properties); return new NStringEntity(userObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:net.jmhertlein.mcanalytics.api.request.PastOnlinePlayerCountRequest.java
@Override public LinkedHashMap<LocalDateTime, Integer> processResponse(JSONObject response) { JSONObject counts = response.getJSONObject("counts"); LinkedHashMap<LocalDateTime, Integer> ret = new LinkedHashMap<>(); for (String s : counts.keySet()) { ret.put(LocalDateTime.parse(s), counts.getInt(s)); }//w ww.jav a 2 s. c o m return ret; }
From source file:net.jmhertlein.mcanalytics.api.request.NewPlayerLoginsRequest.java
@Override public LinkedHashMap<LocalDateTime, Integer> processResponse(JSONObject response) { JSONObject counts = response.getJSONObject("first_login_counts"); LinkedHashMap<LocalDateTime, Integer> ret = new LinkedHashMap<>(); for (String s : counts.keySet()) { ret.put(LocalDateTime.parse(s), counts.getInt(s)); }//from w w w.j av a 2s .c o m return ret; }
From source file:com.espertech.esper.filter.FilterSpecCompiler.java
private static void handleSubselectSelectClauses(int subselectStreamNumber, StatementContext statementContext, ExprSubselectNode subselect, EventType outerEventType, String outerEventTypeName, String outerStreamName, LinkedHashMap<String, Pair<EventType, String>> taggedEventTypes, LinkedHashMap<String, Pair<EventType, String>> arrayEventTypes) throws ExprValidationException { StatementSpecCompiled statementSpec = subselect.getStatementSpecCompiled(); StreamSpecCompiled filterStreamSpec = statementSpec.getStreamSpecs()[0]; ViewFactoryChain viewFactoryChain;/*ww w.ja v a 2 s . com*/ String subselecteventTypeName = null; // construct view factory chain try { if (statementSpec.getStreamSpecs()[0] instanceof FilterStreamSpecCompiled) { FilterStreamSpecCompiled filterStreamSpecCompiled = (FilterStreamSpecCompiled) statementSpec .getStreamSpecs()[0]; subselecteventTypeName = filterStreamSpecCompiled.getFilterSpec().getFilterForEventTypeName(); // A child view is required to limit the stream if (filterStreamSpec.getViewSpecs().length == 0) { throw new ExprValidationException( "Subqueries require one or more views to limit the stream, consider declaring a length or time window"); } // Register filter, create view factories viewFactoryChain = statementContext.getViewService().createFactories(subselectStreamNumber, filterStreamSpecCompiled.getFilterSpec().getResultEventType(), filterStreamSpec.getViewSpecs(), filterStreamSpec.getOptions(), statementContext); subselect.setRawEventType(viewFactoryChain.getEventType()); } else { NamedWindowConsumerStreamSpec namedSpec = (NamedWindowConsumerStreamSpec) statementSpec .getStreamSpecs()[0]; NamedWindowProcessor processor = statementContext.getNamedWindowService() .getProcessor(namedSpec.getWindowName()); viewFactoryChain = statementContext.getViewService().createFactories(0, processor.getNamedWindowType(), namedSpec.getViewSpecs(), namedSpec.getOptions(), statementContext); subselecteventTypeName = namedSpec.getWindowName(); } } catch (ViewProcessingException ex) { throw new ExprValidationException("Error validating subexpression: " + ex.getMessage(), ex); } // the final event type EventType eventType = viewFactoryChain.getEventType(); // determine a stream name unless one was supplied String subexpressionStreamName = filterStreamSpec.getOptionalStreamName(); if (subexpressionStreamName == null) { subexpressionStreamName = "$subselect_" + subselectStreamNumber; } // Named windows don't allow data views if (filterStreamSpec instanceof NamedWindowConsumerStreamSpec) { EPStatementStartMethodHelperValidate .validateNoDataWindowOnNamedWindow(viewFactoryChain.getViewFactoryChain()); } // Streams event types are the original stream types with the stream zero the subselect stream LinkedHashMap<String, Pair<EventType, String>> namesAndTypes = new LinkedHashMap<String, Pair<EventType, String>>(); namesAndTypes.put(subexpressionStreamName, new Pair<EventType, String>(eventType, subselecteventTypeName)); namesAndTypes.put(outerStreamName, new Pair<EventType, String>(outerEventType, outerEventTypeName)); if (taggedEventTypes != null) { for (Map.Entry<String, Pair<EventType, String>> entry : taggedEventTypes.entrySet()) { namesAndTypes.put(entry.getKey(), new Pair<EventType, String>(entry.getValue().getFirst(), entry.getValue().getSecond())); } } if (arrayEventTypes != null) { for (Map.Entry<String, Pair<EventType, String>> entry : arrayEventTypes.entrySet()) { namesAndTypes.put(entry.getKey(), new Pair<EventType, String>(entry.getValue().getFirst(), entry.getValue().getSecond())); } } StreamTypeService subselectTypeService = new StreamTypeServiceImpl(namesAndTypes, statementContext.getEngineURI(), true, true); ViewResourceDelegateUnverified viewResourceDelegateSubselect = new ViewResourceDelegateUnverified(); subselect.setFilterSubqueryStreamTypes(subselectTypeService); // Validate select expression SelectClauseSpecCompiled selectClauseSpec = subselect.getStatementSpecCompiled().getSelectClauseSpec(); if (selectClauseSpec.getSelectExprList().length > 0) { if (selectClauseSpec.getSelectExprList().length > 1) { throw new ExprValidationException("Subquery multi-column select is not allowed in this context."); } SelectClauseElementCompiled element = selectClauseSpec.getSelectExprList()[0]; if (element instanceof SelectClauseExprCompiledSpec) { // validate SelectClauseExprCompiledSpec compiled = (SelectClauseExprCompiledSpec) element; ExprNode selectExpression = compiled.getSelectExpression(); ExprEvaluatorContextStatement evaluatorContextStmt = new ExprEvaluatorContextStatement( statementContext); ExprValidationContext validationContext = new ExprValidationContext(subselectTypeService, statementContext.getMethodResolutionService(), viewResourceDelegateSubselect, statementContext.getSchedulingService(), statementContext.getVariableService(), evaluatorContextStmt, statementContext.getEventAdapterService(), statementContext.getStatementName(), statementContext.getStatementId(), statementContext.getAnnotations(), statementContext.getContextDescriptor()); selectExpression = ExprNodeUtility.getValidatedSubtree(selectExpression, validationContext); subselect.setSelectClause(new ExprNode[] { selectExpression }); subselect.setSelectAsNames(new String[] { compiled.getAssignedName() }); // handle aggregation List<ExprAggregateNode> aggExprNodes = new LinkedList<ExprAggregateNode>(); ExprAggregateNodeUtil.getAggregatesBottomUp(selectExpression, aggExprNodes); if (aggExprNodes.size() > 0) { // Other stream properties, if there is aggregation, cannot be under aggregation. for (ExprAggregateNode aggNode : aggExprNodes) { List<Pair<Integer, String>> propertiesNodesAggregated = ExprNodeUtility .getExpressionProperties(aggNode, true); for (Pair<Integer, String> pair : propertiesNodesAggregated) { if (pair.getFirst() != 0) { throw new ExprValidationException( "Subselect aggregation function cannot aggregate across correlated properties"); } } } // This stream (stream 0) properties must either all be under aggregation, or all not be. List<Pair<Integer, String>> propertiesNotAggregated = ExprNodeUtility .getExpressionProperties(selectExpression, false); for (Pair<Integer, String> pair : propertiesNotAggregated) { if (pair.getFirst() == 0) { throw new ExprValidationException( "Subselect properties must all be within aggregation functions"); } } } } } }