private void initParams(JsonRecord rec) { for (Iterator iter = rec.iterator(); iter.hasNext(); ) { Entry tmp = (Entry) iter.next(); if (tmp.getKey().equals(CMD)) { cmd = (JsonValue) tmp.getValue(); } else if (tmp.getKey().equals(WRITEOPTS)) { writeOpts = (JsonValue) tmp.getValue(); } else if (tmp.getKey().equals(READOPTS)) { readOpts = (JsonValue) tmp.getValue(); } } if (cmd == null) throw new IllegalArgumentException("cmd cannot be null in externalfn()"); try { if (writeOpts == null) { String in = "{outoptions: {adapter: 'com.ibm.jaql.io.stream.StreamOutputAdapter',"; if (mode.equals(new JsonString("push"))) in += "format: 'com.ibm.jaql.io.stream.converter.ArgumentsOutputStream'}}"; else in += "format: 'com.ibm.jaql.io.stream.converter.LineTextOutputStream'}}"; writeOpts = new JsonParser().parse(in); } if (readOpts == null) { String out = "{inoptions: {adapter: 'com.ibm.jaql.io.stream.StreamInputAdapter'," + "format: 'com.ibm.jaql.io.stream.converter.LineTextInputStream'}}"; readOpts = new JsonParser().parse(out); } } catch (ParseException e) { e.printStackTrace(); } }
public ExternalFunctionCallExpr(JsonRecord rec, ArrayList<Expr> exprList) { super(exprList); this.rec = rec; this.mode = (JsonString) rec.get(new JsonString("mode")); if (mode == null) { throw new IllegalArgumentException("mode should be specified: push or streaming"); } initParams(rec); }
public ExternalFunctionCallExpr(JsonRecord rec, Expr[] exprs) throws InstantiationException, IllegalAccessException { super(exprs); this.rec = rec; this.mode = (JsonString) rec.get(new JsonString("mode")); if (mode == null) { throw new IllegalArgumentException("mode should be specified: push or streaming"); } initParams(rec); }
@Override public boolean matches(JsonValue value) throws Exception { if (!(value instanceof JsonRecord)) { return false; } JsonRecord rec = (JsonRecord) value; // assumption: field names are sorted int nr = rec.size(); // number of fields in record int ns = fieldsByName.length; // number of fields in schema int pr = 0; // current field in record int ps = 0; // current field in schema // zip join Iterator<Entry<JsonString, JsonValue>> recIt = rec.iteratorSorted(); Entry<JsonString, JsonValue> recEntry = null; if (nr > 0) recEntry = recIt.next(); while (pr < nr && ps < ns) { Field schemaField = fieldsByName[ps]; JsonString recordFieldName = recEntry.getKey(); // compare int cmp = schemaField.getName().compareTo(recordFieldName); if (cmp < 0) { // field is in schema but not in record if (!schemaField.isOptional) { return false; } ps++; } else if (cmp == 0) { // field is schema and in record if (!schemaField.getSchema().matches(recEntry.getValue())) { return false; } ps++; pr++; if (pr < nr) { assert recIt.hasNext(); recEntry = recIt.next(); } } else { // field is not in schema but in record if (additional == null || !additional.matches(recEntry.getValue())) { return false; } pr++; if (pr < nr) { assert recIt.hasNext(); recEntry = recIt.next(); } } } // only one of them still has fields, i.e., the while loops are exclusive while (pr < nr) { // there are fields left in the record if (additional == null || !additional.matches(recEntry.getValue())) { return false; } pr++; if (pr < nr) { assert recIt.hasNext(); recEntry = recIt.next(); } } assert !recIt.hasNext(); while (ps < ns) { // therea are fields left in the schema if (!fieldsByName[ps].isOptional) { return false; } ps++; } // everything ok return true; }
@Override public boolean isMappable(int i) { return i == 0 && ((JsonBool) rec.get(new JsonString("perPartition"))).get() == true; }