private void doAddOp(int i, Fragment fragment, String s, int j) { fragment.mFragmentManager = mManager; if (s != null) { if (fragment.mTag != null && !s.equals(fragment.mTag)) throw new IllegalStateException( (new StringBuilder()) .append("Can't change tag of fragment ") .append(fragment) .append(": was ") .append(fragment.mTag) .append(" now ") .append(s) .toString()); fragment.mTag = s; } if (i != 0) { if (fragment.mFragmentId != 0 && fragment.mFragmentId != i) throw new IllegalStateException( (new StringBuilder()) .append("Can't change container ID of fragment ") .append(fragment) .append(": was ") .append(fragment.mFragmentId) .append(" now ") .append(i) .toString()); fragment.mFragmentId = i; fragment.mContainerId = i; } Op op = new Op(); op.cmd = j; op.fragment = fragment; addOp(op); }
public FragmentTransaction remove(Fragment fragment) { Op op = new Op(); op.cmd = 3; op.fragment = fragment; addOp(op); return this; }
public FragmentTransaction show(Fragment fragment) { Op op = new Op(); op.cmd = 5; op.fragment = fragment; addOp(op); return this; }
public FragmentTransaction detach(Fragment fragment) { Op op = new Op(); op.cmd = 6; op.fragment = fragment; addOp(op); return this; }
/** * @param operator * @param parent * @return * @throws JSONException * @throws JsonParseException * @throws JsonMappingException * @throws IOException * @throws Exception assumption: each operator only has one parent but may have many children */ Op extractOp(JSONObject operator) throws JSONException, JsonParseException, JsonMappingException, IOException, Exception { String[] names = JSONObject.getNames(operator); if (names.length != 1) { throw new Exception("Expect only one operator in " + operator.toString()); } else { String opName = names[0]; JSONObject attrObj = (JSONObject) operator.get(opName); Map<String, String> attrs = new TreeMap<>(); List<Op> children = new ArrayList<>(); String id = null; String outputVertexName = null; for (String attrName : JSONObject.getNames(attrObj)) { if (attrName.equals("children")) { Object childrenObj = attrObj.get(attrName); if (childrenObj instanceof JSONObject) { if (((JSONObject) childrenObj).length() != 0) { children.add(extractOp((JSONObject) childrenObj)); } } else if (childrenObj instanceof JSONArray) { if (((JSONArray) childrenObj).length() != 0) { JSONArray array = ((JSONArray) childrenObj); for (int index = 0; index < array.length(); index++) { children.add(extractOp(array.getJSONObject(index))); } } } else { throw new Exception( "Unsupported operator " + this.name + "'s children operator is neither a jsonobject nor a jsonarray"); } } else { if (attrName.equals("OperatorId:")) { id = attrObj.get(attrName).toString(); } else if (attrName.equals("outputname:")) { outputVertexName = attrObj.get(attrName).toString(); } else { if (!attrObj.get(attrName).toString().isEmpty()) { attrs.put(attrName, attrObj.get(attrName).toString()); } } } } Op op = new Op(opName, id, outputVertexName, children, attrs, operator, this, parser); if (!children.isEmpty()) { for (Op child : children) { child.parent = op; } } else { this.rootOps.add(op); } return op; } }
/** Tests {@link OpService#op(String, Object...)}. */ @Test public void testOpByName() { final DoubleType value = new DoubleType(123.456); final Op op = ops.op("test.infinity", value); assertSame(InfinityOp.class, op.getClass()); assertFalse(Double.isInfinite(value.get())); op.run(); assertTrue(Double.isInfinite(value.get())); }
public Address(int type, int size, int address) { this.type = type; this.size = size; this.address = address; if (Op.matches(type, Op.MEM | Op.REG | Op.FPUREG)) { dynamic = true; } }
/** Tests op lookups by class. */ @Test public void testMatchingByClass() { Op op = ops.op("test.arrr!", (Object) null); assertSame(FirstMate.class, op.getClass()); op = ops.op("test.arrr!", (EyePatch) null); assertSame(FirstMate.class, op.getClass()); op = ops.op("test.arrr!", (Booty) null); assertSame(FirstMate.class, op.getClass()); op = ops.op("test.arrr!", EyePatch.class); assertSame(FirstMate.class, op.getClass()); op = ops.op("test.arrr!", Booty.class); assertSame(Captain.class, op.getClass()); }
void addOp(Op op) { if (mHead == null) { mTail = op; mHead = op; } else { op.prev = mTail; mTail.next = op; mTail = op; } op.enterAnim = mEnterAnim; op.exitAnim = mExitAnim; op.popEnterAnim = mPopEnterAnim; op.popExitAnim = mPopExitAnim; mNumOp = 1 + mNumOp; }
public Schema schema() { return subOp.schema().subset(keys); }
public void print(Printer printer, int indentFlag, String type, Vertex callingVertex) throws JSONException, Exception { // print vertexname if (parser.printSet.contains(this) && !hasMultiReduceOp) { if (type != null) { printer.println( TezJsonParser.prefixString(indentFlag, "<-") + " Please refer to the previous " + this.name + " [" + type + "]"); } else { printer.println( TezJsonParser.prefixString(indentFlag, "<-") + " Please refer to the previous " + this.name); } return; } parser.printSet.add(this); if (type != null) { printer.println( TezJsonParser.prefixString(indentFlag, "<-") + this.name + " [" + type + "]" + this.executionMode); } else if (this.name != null) { printer.println(TezJsonParser.prefixString(indentFlag) + this.name + this.executionMode); } // print operators if (hasMultiReduceOp && !(callingVertex.vertexType == VertexType.UNION)) { // find the right op Op choose = null; for (Op op : this.rootOps) { if (op.outputVertexName.equals(callingVertex.name)) { choose = op; } } if (choose != null) { choose.print(printer, indentFlag, false); } else { throw new Exception( "Can not find the right reduce output operator for vertex " + this.name); } } else { for (Op op : this.rootOps) { // dummy vertex is treated as a branch of a join operator if (this.dummy) { op.print(printer, indentFlag, true); } else { op.print(printer, indentFlag, false); } } } if (vertexType == VertexType.UNION) { // print dependent vertexs indentFlag++; for (int index = 0; index < this.parentConnections.size(); index++) { Connection connection = this.parentConnections.get(index); connection.from.print(printer, indentFlag, connection.type, this); } } }
@Override public Node forAssignment(Assignment that) { // System.out.println("PreDesugar entry"); // Here there are three sorts of rewrite to consider: // (a) If this is a compound assignment, rewrite to use ordinary assignment. // (b) If the lhs is a tuple, rewrite into a set of individual assignments. // (c) If the lhs is a subscript expression, rewrite to a method call. List<Lhs> lhs = that.getLhs(); Option<FunctionalRef> assignOp = that.getAssignOp(); Expr rhs = that.getRhs(); List<CompoundAssignmentInfo> assignmentInfos = that.getAssignmentInfos(); if (!Shell.getAssignmentPreDesugaring()) { // System.out.println("Did not PreDesugar"); return super.forAssignment(that); } else if (assignOp.isSome() || lhs.size() > 1) { // System.out.println("Compound/tuple PreDesugar"); // Compound and/or tuple assignment // The basic idea is to transform `(a, b.field, c[sub1,sub2]) := e` into // `do (ta, tb, tc, tsub1, tsub2, (t1, t2, t3)) = (a, b, c, sub1, sub2, e) // a := t1; tb.field := t2; tc[tsub1, tsub2] := t3 end` // (TODO) Unfortunately, currently we don't handle nested binding tuples. // For now, we'll just transform it into // `do (ta, tb, tc, tsub1, tsub2) = (a, b, c, sub1, sub2) // (t1, t2, t3) = e // a := t1; tb.field := t2; tc[tsub1, tsub2] := t3 end` // which merely loses a bit of potential parallelism. // We omit the first tuple binding if the tuple is empty. // If it is a compound assignment `(a, b.field, c[sub1,sub2]) OP= e`, it becomes // `do (ta, tb, tc, tsub1, tsub2) = (a, b, c, sub1, sub2) // (t1, t2, t3) = (ta, tb, tc[tsub1, tsub2]) OP e // a := t1; tb.field := t2; tc[tsub1, tsub2] := t3 end` List<LValue> exprLValues = Useful.list(); List<LValue> otherLValues = Useful.list(); List<Expr> otherExprs = Useful.list(); List<Expr> assignments = Useful.list(); boolean isCompound = assignOp.isSome(); List<Expr> accesses = Useful.list(); Span thatSpan = NodeUtil.getSpan(that); for (Lhs lh : lhs) { Span lhSpan = NodeUtil.getSpan((Expr) lh); Id tempId = DesugarerUtil.gensymId(lhSpan, "e"); VarRef tempVar = ExprFactory.makeVarRef(lhSpan, tempId); exprLValues = Useful.snoc(exprLValues, NodeFactory.makeLValue(lhSpan, tempId)); if (lh instanceof SubscriptExpr) { SubscriptExpr lhsub = (SubscriptExpr) lh; Expr obj = lhsub.getObj(); Span objSpan = NodeUtil.getSpan(obj); List<Expr> subs = lhsub.getSubs(); Id baseTempId = DesugarerUtil.gensymId(objSpan, "b"); VarRef baseTempVar = ExprFactory.makeVarRef(objSpan, baseTempId); otherLValues = Useful.snoc(otherLValues, NodeFactory.makeLValue(objSpan, baseTempId)); otherExprs = Useful.snoc(otherExprs, obj); List<Expr> subTempVars = Useful.list(); for (Expr sub : lhsub.getSubs()) { Span subSpan = NodeUtil.getSpan(sub); Id subTempId = DesugarerUtil.gensymId(subSpan, "s"); subTempVars = Useful.snoc(subTempVars, ExprFactory.makeVarRef(subSpan, subTempId)); otherLValues = Useful.snoc(otherLValues, NodeFactory.makeLValue(subSpan, subTempId)); } otherExprs = Useful.concat(otherExprs, subs); SubscriptExpr newLhs = ExprFactory.makeSubscriptExpr( NodeUtil.getSpan(lhsub), baseTempVar, subTempVars, lhsub.getOp(), lhsub.getStaticArgs()); if (isCompound) accesses = Useful.snoc(accesses, newLhs); assignments = Useful.snoc(assignments, ExprFactory.makeAssignment(thatSpan, newLhs, tempVar)); } else if (lh instanceof FieldRef) { FieldRef lhref = (FieldRef) lh; Expr obj = lhref.getObj(); Span objSpan = NodeUtil.getSpan(obj); Id objTempId = DesugarerUtil.gensymId(objSpan, "o"); VarRef objTempVar = ExprFactory.makeVarRef(objSpan, objTempId); otherLValues = Useful.snoc(otherLValues, NodeFactory.makeLValue(objSpan, objTempId)); otherExprs = Useful.snoc(otherExprs, obj); FieldRef newLhs = ExprFactory.makeFieldRef(NodeUtil.getSpan(lhref), objTempVar, lhref.getField()); if (isCompound) accesses = Useful.snoc(accesses, newLhs); assignments = Useful.snoc(assignments, ExprFactory.makeAssignment(thatSpan, newLhs, tempVar)); } else if (lh instanceof VarRef) { VarRef lhvar = (VarRef) lh; Span varSpan = NodeUtil.getSpan(lhvar); Id varTempId = DesugarerUtil.gensymId(varSpan, "v"); VarRef varTempVar = ExprFactory.makeVarRef(varSpan, varTempId); otherLValues = Useful.snoc(otherLValues, NodeFactory.makeLValue(varSpan, varTempId)); otherExprs = Useful.snoc(otherExprs, lhvar); if (isCompound) accesses = Useful.snoc(accesses, varTempVar); assignments = Useful.snoc(assignments, ExprFactory.makeAssignment(thatSpan, lhvar, tempVar)); } else { bug(that, "Malformed assignment LHS"); } } Expr result = ExprFactory.makeBlock(thatSpan, assignments); if (otherExprs.size() > 0) { Expr otherRhs = ExprFactory.makeMaybeTupleExpr(thatSpan, otherExprs); result = ExprFactory.makeLocalVarDecl(thatSpan, otherLValues, otherRhs, result); } Expr newRhs = isCompound ? ExprFactory.makeOpExpr( NodeUtil.spanTwo(assignOp.unwrap(), rhs), assignOp.unwrap(), ExprFactory.makeMaybeTupleExpr(thatSpan, accesses), rhs) : rhs; result = ExprFactory.makeLocalVarDecl(thatSpan, exprLValues, newRhs, result); return (Expr) recur(result); } else if (lhs.get(0) instanceof SubscriptExpr) { // System.out.println("PreDesugar single subscript expr"); // Subscripted assignment SubscriptExpr lhExpr = (SubscriptExpr) lhs.get(0); Expr obj = lhExpr.getObj(); List<Expr> subs = lhExpr.getSubs(); Option<Op> op = lhExpr.getOp(); List<StaticArg> staticArgs = lhExpr.getStaticArgs(); if (!op.isSome()) bug(lhExpr, "Subscript operator expected"); Op knownOp = op.unwrap(); Expr result = ExprFactory.makeMethodInvocation( that, obj, NodeFactory.makeOp(knownOp, knownOp.getText() + ":="), staticArgs, ExprFactory.makeTupleExpr(NodeUtil.spanTwo(knownOp, rhs), Useful.cons(rhs, subs))); return (Expr) recur(result); } else { // System.out.println("PreDesugar single expr of class " + lhs.get(0).getClass().getName()); return super.forAssignment(that); } }
@Override public String toString() { return "FilterDto op: " + operator.toString() + ", values: " + values; }
public String toString() { String t2 = second.isType(VALUE) ? "'" + second + "'" : second.toString(); return "(" + getFirst() + getType().toSymbol() + t2 + ')'; }
public void run() { label0: { if (FragmentManagerImpl.DEBUG) Log.v("FragmentManager", (new StringBuilder()).append("Run: ").append(this).toString()); if (mAddToBackStack && mIndex < 0) throw new IllegalStateException("addToBackStack() called after commit()"); bumpBackStackNesting(1); Op op = mHead; label1: do { if (op == null) break label0; switch (op.cmd) { default: break label1; case 7: // '\007' Fragment fragment7 = op.fragment; fragment7.mNextAnim = op.enterAnim; mManager.attachFragment(fragment7, mTransition, mTransitionStyle); break; case 6: // '\006' Fragment fragment6 = op.fragment; fragment6.mNextAnim = op.exitAnim; mManager.detachFragment(fragment6, mTransition, mTransitionStyle); break; case 5: // '\005' Fragment fragment5 = op.fragment; fragment5.mNextAnim = op.enterAnim; mManager.showFragment(fragment5, mTransition, mTransitionStyle); break; case 4: // '\004' Fragment fragment4 = op.fragment; fragment4.mNextAnim = op.exitAnim; mManager.hideFragment(fragment4, mTransition, mTransitionStyle); break; case 3: // '\003' Fragment fragment3 = op.fragment; fragment3.mNextAnim = op.exitAnim; mManager.removeFragment(fragment3, mTransition, mTransitionStyle); break; case 2: // '\002' Fragment fragment1 = op.fragment; if (mManager.mAdded != null) { for (int i = 0; i < mManager.mAdded.size(); i++) { Fragment fragment2 = (Fragment) mManager.mAdded.get(i); if (FragmentManagerImpl.DEBUG) Log.v( "FragmentManager", (new StringBuilder()) .append("OP_REPLACE: adding=") .append(fragment1) .append(" old=") .append(fragment2) .toString()); if (fragment1 != null && fragment2.mContainerId != fragment1.mContainerId) continue; if (fragment2 == fragment1) { fragment1 = null; op.fragment = null; continue; } if (op.removed == null) op.removed = new ArrayList(); op.removed.add(fragment2); fragment2.mNextAnim = op.exitAnim; if (mAddToBackStack) { fragment2.mBackStackNesting = 1 + fragment2.mBackStackNesting; if (FragmentManagerImpl.DEBUG) Log.v( "FragmentManager", (new StringBuilder()) .append("Bump nesting of ") .append(fragment2) .append(" to ") .append(fragment2.mBackStackNesting) .toString()); } mManager.removeFragment(fragment2, mTransition, mTransitionStyle); } } if (fragment1 != null) { fragment1.mNextAnim = op.enterAnim; mManager.addFragment(fragment1, false); } break; case 1: // '\001' Fragment fragment = op.fragment; fragment.mNextAnim = op.enterAnim; mManager.addFragment(fragment, false); break; } op = op.next; } while (true); throw new IllegalArgumentException( (new StringBuilder()).append("Unknown cmd: ").append(op.cmd).toString()); } mManager.moveToState(mManager.mCurState, mTransition, mTransitionStyle, true); if (mAddToBackStack) mManager.addBackStackState(this); }
public int cost(CostModel model) { return subOp.cost(model); }
/** * Override the preAppend for checkAndPut and checkAndDelete, as we need the ability to a) set the * TimeRange for the Get being done and b) return something back to the client to indicate * success/failure */ @SuppressWarnings("deprecation") @Override public Result preAppend( final ObserverContext<RegionCoprocessorEnvironment> e, final Append append) throws IOException { byte[] opBuf = append.getAttribute(OPERATION_ATTRIB); if (opBuf == null) { return null; } Op op = Op.values()[opBuf[0]]; long clientTimestamp = HConstants.LATEST_TIMESTAMP; byte[] clientTimestampBuf = append.getAttribute(MAX_TIMERANGE_ATTRIB); if (clientTimestampBuf != null) { clientTimestamp = Bytes.toLong(clientTimestampBuf); } boolean hadClientTimestamp = (clientTimestamp != HConstants.LATEST_TIMESTAMP); if (hadClientTimestamp) { // Prevent race condition of creating two sequences at the same timestamp // by looking for a sequence at or after the timestamp at which it'll be // created. if (op == Op.CREATE_SEQUENCE) { clientTimestamp++; } } else { clientTimestamp = EnvironmentEdgeManager.currentTimeMillis(); clientTimestampBuf = Bytes.toBytes(clientTimestamp); } RegionCoprocessorEnvironment env = e.getEnvironment(); // We need to set this to prevent region.append from being called e.bypass(); e.complete(); HRegion region = env.getRegion(); byte[] row = append.getRow(); region.startRegionOperation(); try { Integer lid = region.getLock(null, row, true); try { KeyValue keyValue = append.getFamilyMap().values().iterator().next().iterator().next(); byte[] family = keyValue.getFamily(); byte[] qualifier = keyValue.getQualifier(); Get get = new Get(row); get.setTimeRange(MetaDataProtocol.MIN_TABLE_TIMESTAMP, clientTimestamp); get.addColumn(family, qualifier); Result result = region.get(get); if (result.isEmpty()) { if (op == Op.DROP_SEQUENCE || op == Op.RESET_SEQUENCE) { return getErrorResult( row, clientTimestamp, SQLExceptionCode.SEQUENCE_UNDEFINED.getErrorCode()); } } else { if (op == Op.CREATE_SEQUENCE) { return getErrorResult( row, clientTimestamp, SQLExceptionCode.SEQUENCE_ALREADY_EXIST.getErrorCode()); } } Mutation m = null; switch (op) { case RESET_SEQUENCE: KeyValue currentValueKV = result.raw()[0]; long expectedValue = PDataType.LONG .getCodec() .decodeLong(append.getAttribute(CURRENT_VALUE_ATTRIB), 0, null); long value = PDataType.LONG .getCodec() .decodeLong(currentValueKV.getBuffer(), currentValueKV.getValueOffset(), null); // Timestamp should match exactly, or we may have the wrong sequence if (expectedValue != value || currentValueKV.getTimestamp() != clientTimestamp) { return new Result( Collections.singletonList( KeyValueUtil.newKeyValue( row, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_BYTES, currentValueKV.getTimestamp(), ByteUtil.EMPTY_BYTE_ARRAY))); } m = new Put(row, currentValueKV.getTimestamp()); m.getFamilyMap().putAll(append.getFamilyMap()); break; case DROP_SEQUENCE: m = new Delete(row, clientTimestamp, null); break; case CREATE_SEQUENCE: m = new Put(row, clientTimestamp); m.getFamilyMap().putAll(append.getFamilyMap()); break; } if (!hadClientTimestamp) { for (List<KeyValue> kvs : m.getFamilyMap().values()) { for (KeyValue kv : kvs) { kv.updateLatestStamp(clientTimestampBuf); } } } @SuppressWarnings("unchecked") Pair<Mutation, Integer>[] mutations = new Pair[1]; mutations[0] = new Pair<Mutation, Integer>(m, lid); region.batchMutate(mutations); long serverTimestamp = MetaDataUtil.getClientTimeStamp(m); // Return result with single KeyValue. The only piece of information // the client cares about is the timestamp, which is the timestamp of // when the mutation was actually performed (useful in the case of . return new Result( Collections.singletonList( KeyValueUtil.newKeyValue( row, PhoenixDatabaseMetaData.SEQUENCE_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_BYTES, serverTimestamp, SUCCESS_VALUE))); } finally { region.releaseRowLock(lid); } } catch (Throwable t) { ServerUtil.throwIOException("Increment of sequence " + Bytes.toStringBinary(row), t); return null; // Impossible } finally { region.closeRegionOperation(); } }
public static void main(String[] args) { Scanner user_input = new Scanner(System.in); try { String text; Op operator; Calc<?> calD; Expr expr; boolean parseExpression = true; calD = new CalcDouble<Double>(Double.class); expr = new Expr(calD); System.out.println("Operatorer: " + Op.toString(calD.operators)); System.out.println("i: heltall d: desimal f: flyttall parse trace h: help s: slutt"); do { System.out.print(": "); text = user_input.nextLine(); calD.saveStack(); // Check if the text is a valid operator for the type of // arguments operator = Op.operator(text, calD.operators); if (operator != null) { calD.op(operator); } else { // If the operator exists, but is invalid for the type write // that operator = Op.operator(text); if (operator != null) System.out.println( "Operator " + operator.abbrev() + " ugyldig for " + calD.type.getSimpleName() + "."); else { switch (text.toLowerCase()) { case "s": break; case "i": calD.clear(); calD = new CalcBigInteger<BigInteger>(BigInteger.class); expr.setCalc(calD); System.out.println("Operatorer: " + Op.toString(calD.operators)); break; case "d": calD.clear(); calD = new CalcBigDecimal<BigDecimal>(BigDecimal.class); expr.setCalc(calD); System.out.println("Operatorer: " + Op.toString(calD.operators)); break; case "f": calD.clear(); calD = new CalcDouble<Double>(Double.class); expr.setCalc(calD); System.out.println("Operatorer: " + Op.toString(calD.operators)); break; case "": case "help": case "h": System.out.println("Operatorer: " + Op.toString(calD.operators)); System.out.println( "i: heltall d: desimal f: flyttall parse trace h: help s: slutt"); break; case "parse": parseExpression = !parseExpression; if (parseExpression) System.out.println("Parsing på."); else System.out.println("Parsing av."); break; case "trace": expr.setTrace(); break; default: if (parseExpression) { if (expr.parse(text)) expr.calculate(); } else { calD.enter(text); } } } } } while (!text.equals("s")); } catch (Exception e) { System.out.println("Alvorlig feil: " + e.getMessage()); } finally { user_input.close(); } System.out.println("Avsluttet kalkulator"); }
/** * Add a list of {@link Op}s to the {@link OpsBuilder}. * * @param ops the {@link Op}s * @return the {@link OpsBuilder} */ public DocBuilder withOps(List<Op> ops) { for (Op op : ops) { op.add(this); // These operations call the operations below to build the doc. } return this; }