/* * Make encoding (compresstype = none, blocksize=...). We do this for the case * where the user has not specified an encoding for the column. */ List * default_column_encoding_clause(void) { DefElem *e1 = makeDefElem("compresstype", (Node *)makeString("none")); DefElem *e2 = makeDefElem("blocksize", (Node *)makeInteger(DEFAULT_APPENDONLY_BLOCK_SIZE)); DefElem *e3 = makeDefElem("compresslevel", (Node *)makeInteger(0)); return list_make3(e1, e2, e3); }
void PowercastTxControl3Layer::processPacket(ProtocolPacket *xBeePacket) { //Serial.println("processPacket"); //Serial.println(xBeePacket->packetType); //Serial.println(currentState); if (currentState == STATE_OFF && xBeePacket->packetType == TYPE_PING) { if (measurementObject != NULL) { measurementObject->savePacketEventToFile(IS_TX, true, xBeePacket); } byte rssiThreshold = xBeePacket->packetData[0]; Serial.print(F("RSSI threshold of communication ")); Serial.println(rssiThreshold); Serial.print(F("RSSI of communication the packet")); Serial.println(xBeePacket->receivedPacketRssi); if (xBeePacket->receivedPacketRssi < rssiThreshold) { Serial.println(F("EVENT hurray!")); eventReceivedPing(xBeePacket); } } if ((currentState == STATE_OFF_POWER_PROBE || currentState == STATE_ON) && xBeePacket->packetType == TYPE_VOLTAGE_RESPONSE) { if (measurementObject != NULL) { measurementObject->savePacketEventToFile(IS_TX, true, xBeePacket); } int receivedVoltage = makeInteger(xBeePacket->packetData[1], xBeePacket->packetData[2]); int voltageThreshold = makeInteger(xBeePacket->packetData[3], xBeePacket->packetData[4]); Serial.print(F("Received voltage ")); Serial.println(receivedVoltage); Serial.print(F("Voltage threshold ")); Serial.println(voltageThreshold); lastPowerProbeReceived = getCurrentTimeMiliseconds(); if (receivedVoltage > voltageThreshold) { Serial.println(F("ABOVE")); eventPwrProbeReceivedAboveTh(); } else { Serial.println(F("BELOW")); eventPwrProbeReceivedBelowTh(); } } }
void PowercastTxControl2Layer::processPacket(ProtocolPacket *xBeePacket) { //Serial.println("processPacket"); if (xBeePacket->packetType == TYPE_PING) { if (measurementObject != NULL) { measurementObject->savePacketEventToFile(IS_TX, true, xBeePacket); } if (xBeePacket->receivedPacketRssi < RSSI_THRESHOLD) { eventReceivedPing(); } } else if (xBeePacket->packetType == TYPE_VOLTAGE_RESPONSE) { if (measurementObject != NULL) { measurementObject->savePacketEventToFile(IS_TX, true, xBeePacket); } int receivedVoltage = makeInteger(xBeePacket->packetData[1], xBeePacket->packetData[2]); if (receivedVoltage > VOLTAGE_THRESHOLD) { eventPwrProbeReceivedAboveTh(); } else { eventPwrProbeReceivedBelowTh(); } } }
int main() { int* integer = makeInteger(5); struct Data data1 = makeData1(5); struct Data* data2 = makeData2(5); free(integer); free(data2); return 0; }
/* * Create a DefElem setting "oids" to the specified value. */ DefElem * defWithOids(bool value) { DefElem *f = makeNode(DefElem); f->defname = "oids"; f->arg = (Node *) makeInteger(value); return f; }
/* * Make encoding (compresstype = none, blocksize=...) based on * currently configured defaults. */ List * default_column_encoding_clause(void) { const StdRdOptions *ao_opts = currentAOStorageOptions(); DefElem *e1, *e2, *e3; if (ao_opts->compresstype) { e1 = makeDefElem("compresstype", (Node *)makeString(pstrdup(ao_opts->compresstype))); } else { e1 = makeDefElem("compresstype", (Node *)makeString("none")); } e2 = makeDefElem("blocksize", (Node *)makeInteger(ao_opts->blocksize)); e3 = makeDefElem("compresslevel", (Node *)makeInteger(ao_opts->compresslevel)); return list_make3(e1, e2, e3); }
/* * nodeRead - * Slightly higher-level reader. * * This routine applies some semantic knowledge on top of the purely * lexical tokenizer pg_strtok(). It can read * * Value token nodes (integers, floats, or strings); * * General nodes (via parseNodeString() from readfuncs.c); * * Lists of the above; * * Lists of integers or OIDs. * The return value is declared void *, not Node *, to avoid having to * cast it explicitly in callers that assign to fields of different types. * * External callers should always pass NULL/0 for the arguments. Internally * a non-NULL token may be passed when the upper recursion level has already * scanned the first token of a node's representation. * * We assume pg_strtok is already initialized with a string to read (hence * this should only be invoked from within a stringToNode operation). */ void * nodeRead(char *token, int tok_len) { Node *result; NodeTag type; if (token == NULL) /* need to read a token? */ { token = pg_strtok(&tok_len); if (token == NULL) /* end of input */ return NULL; } type = nodeTokenType(token, tok_len); switch (type) { case LEFT_BRACE: result = parseNodeString(); token = pg_strtok(&tok_len); if (token == NULL || token[0] != '}') elog(ERROR, "did not find '}' at end of input node"); break; case LEFT_PAREN: { List *l = NIL; /*---------- * Could be an integer list: (i int int ...) * or an OID list: (o int int ...) * or a list of nodes/values: (node node ...) *---------- */ token = pg_strtok(&tok_len); if (token == NULL) elog(ERROR, "unterminated List structure"); if (tok_len == 1 && token[0] == 'i') { /* List of integers */ for (;;) { int val; char *endptr; token = pg_strtok(&tok_len); if (token == NULL) elog(ERROR, "unterminated List structure"); if (token[0] == ')') break; val = (int) strtol(token, &endptr, 10); if (endptr != token + tok_len) elog(ERROR, "unrecognized integer: \"%.*s\"", tok_len, token); l = lappend_int(l, val); } } else if (tok_len == 1 && token[0] == 'o') { /* List of OIDs */ for (;;) { Oid val; char *endptr; token = pg_strtok(&tok_len); if (token == NULL) elog(ERROR, "unterminated List structure"); if (token[0] == ')') break; val = (Oid) strtoul(token, &endptr, 10); if (endptr != token + tok_len) elog(ERROR, "unrecognized OID: \"%.*s\"", tok_len, token); l = lappend_oid(l, val); } } else { /* List of other node types */ for (;;) { /* We have already scanned next token... */ if (token[0] == ')') break; l = lappend(l, nodeRead(token, tok_len)); token = pg_strtok(&tok_len); if (token == NULL) elog(ERROR, "unterminated List structure"); } } result = (Node *) l; break; } case RIGHT_PAREN: elog(ERROR, "unexpected right parenthesis"); result = NULL; /* keep compiler happy */ break; case OTHER_TOKEN: if (tok_len == 0) { /* must be "<>" --- represents a null pointer */ result = NULL; } else { elog(ERROR, "unrecognized token: \"%.*s\"", tok_len, token); result = NULL; /* keep compiler happy */ } break; case T_Integer: /* * we know that the token terminates on a char atol will stop at */ result = (Node *) makeInteger(atol(token)); break; case T_Float: { char *fval = (char *) palloc(tok_len + 1); memcpy(fval, token, tok_len); fval[tok_len] = '\0'; result = (Node *) makeFloat(fval); } break; case T_String: /* need to remove leading and trailing quotes, and backslashes */ result = (Node *) makeString(debackslash(token + 1, tok_len - 2)); break; case T_BitString: { char *val = palloc(tok_len); /* skip leading 'b' */ strncpy(val, token + 1, tok_len - 1); val[tok_len - 1] = '\0'; result = (Node *) makeBitString(val); break; } default: elog(ERROR, "unrecognized node type: %d", (int) type); result = NULL; /* keep compiler happy */ break; } return (void *) result; }
/* * nodeRead - * Slightly higher-level reader. * * This routine applies some semantic knowledge on top of the purely * lexical tokenizer pg_strtok(). It can read * * Value token nodes (integers, floats, or strings); * * General nodes (via parseNodeString() from readfuncs.c); * * Lists of the above; * * Lists of integers or OIDs. * The return value is declared void *, not Node *, to avoid having to * cast it explicitly in callers that assign to fields of different types. * * External callers should always pass NULL/0 for the arguments. Internally * a non-NULL token may be passed when the upper recursion level has already * scanned the first token of a node's representation. * * We assume pg_strtok is already initialized with a string to read (hence * this should only be invoked from within a stringToNode operation). */ void * nodeRead(char *token, int tok_len) { Node *result; NodeTag type; if (token == NULL) /* need to read a token? */ { token = pg_strtok(&tok_len); if (token == NULL) /* end of input */ return NULL; } type = nodeTokenType(token, tok_len); switch ((int)type) { case LEFT_BRACE: result = parseNodeString(); token = pg_strtok(&tok_len); /* * CDB: Check for extra fields left over following the ones that * were consumed by the node reader function. If this tree was * read from the catalog, it might have been stored by a future * release which may have added fields that we don't know about. */ while (token && token[0] == ':') { /* * Check for special :prereq tag that a future release may have * inserted to tell us that the node's semantics are not * downward compatible. The node reader function should have * consumed any such tags for features that it supports. If a * :prereq is left to be seen here, that means its feature isn't * implemented in this release and we must reject the statement. * The tag should be followed by a concise feature name or * release id that can be shown to the user in an error message. */ if (tok_len == 7 && memcmp(token, ":prereq", 7) == 0) { token = pg_strtok(&tok_len); token = debackslash(token, tok_len); ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("This operation requires a feature " "called \"%.*s\" which is not " "supported in this version of %s.", tok_len, token, PACKAGE_NAME) )); } /* * Other extra fields can safely be ignored. They are assumed * downward compatible unless a :prereq tag tells us otherwise. */ nodeReadSkip(); ereport(DEBUG2, (errmsg("nodeRead: unknown option '%.*s' ignored", tok_len, token), errdetail("Skipped '%.*s' at offset %d in %s", (int)(pg_strtok_ptr - token), token, (int)(token - pg_strtok_begin), pg_strtok_begin) )); token = pg_strtok(&tok_len); } if (token == NULL ) elog(ERROR, "did not find '}' at end of input node"); if (token[0] != '}') elog(ERROR, "did not find '}' at end of input node, instead found %s",token); break; case LEFT_PAREN: { List *l = NIL; /*---------- * Could be an integer list: (i int int ...) * or an OID list: (o int int ...) * or a list of nodes/values: (node node ...) *---------- */ token = pg_strtok(&tok_len); if (token == NULL) elog(ERROR, "unterminated List structure"); if (tok_len == 1 && token[0] == 'i') { /* List of integers */ for (;;) { int val; char *endptr; token = pg_strtok(&tok_len); if (token == NULL) elog(ERROR, "unterminated List structure"); if (token[0] == ')') break; val = (int) strtol(token, &endptr, 10); if (endptr != token + tok_len) elog(ERROR, "unrecognized integer: \"%.*s\"", tok_len, token); l = lappend_int(l, val); } } else if (tok_len == 1 && token[0] == 'o') { /* List of OIDs */ for (;;) { Oid val; char *endptr; token = pg_strtok(&tok_len); if (token == NULL) elog(ERROR, "unterminated List structure"); if (token[0] == ')') break; val = (Oid) strtoul(token, &endptr, 10); if (endptr != token + tok_len) elog(ERROR, "unrecognized OID: \"%.*s\"", tok_len, token); l = lappend_oid(l, val); } } else { /* List of other node types */ for (;;) { /* We have already scanned next token... */ if (token[0] == ')') break; l = lappend(l, nodeRead(token, tok_len)); token = pg_strtok(&tok_len); if (token == NULL) elog(ERROR, "unterminated List structure"); } } result = (Node *) l; break; } case RIGHT_PAREN: elog(ERROR, "unexpected right parenthesis"); result = NULL; /* keep compiler happy */ break; case OTHER_TOKEN: if (tok_len == 0) { /* must be "<>" --- represents a null pointer */ result = NULL; } else { elog(ERROR, "unrecognized token: \"%.*s\"", tok_len, token); result = NULL; /* keep compiler happy */ } break; case T_Integer: /* * we know that the token terminates on a char atol will stop at */ result = (Node *) makeInteger(atol(token)); break; case T_Float: { char *fval = (char *) palloc(tok_len + 1); memcpy(fval, token, tok_len); fval[tok_len] = '\0'; result = (Node *) makeFloat(fval); } break; case T_String: /* need to remove leading and trailing quotes, and backslashes */ result = (Node *) makeString(debackslash(token + 1, tok_len - 2)); break; case T_BitString: { char *val = palloc(tok_len); /* skip leading 'b' */ memcpy(val, token + 1, tok_len - 1); val[tok_len - 1] = '\0'; result = (Node *) makeBitString(val); break; } default: elog(ERROR, "unrecognized node type: %d", (int) type); result = NULL; /* keep compiler happy */ break; } return (void *) result; }
/* MPP-6923: */ static List * AlterResqueueCapabilityEntry( List *stmtOptIdList, Oid queueid, ListCell *initcell, bool bCreate) { ListCell *lc; List *elems = NIL; List *dropelems = NIL; List *dupcheck = NIL; HeapTuple tuple; cqContext *pcqCtx; cqContext cqc; Relation rel = NULL; bool bWithout = false; TupleDesc tupdesc = NULL; #ifdef USE_ASSERT_CHECKING { DefElem *defel = (DefElem *) lfirst(initcell); Assert(0 == strcmp(defel->defname, "withliststart")); } #endif initcell = lnext(initcell); /* walk the original list and build a list of valid entries */ for_each_cell(lc, initcell) { DefElem *defel = (DefElem *) lfirst(lc); Oid resTypeOid = InvalidOid; int resTypeInt = 0; List *pentry = NIL; Value *pKeyVal = NULL; Value *pStrVal = NULL; if (!bWithout && (strcmp(defel->defname, "withoutliststart") == 0)) { bWithout = true; rel = heap_open(ResourceTypeRelationId, RowExclusiveLock); tupdesc = RelationGetDescr(rel); goto L_loop_cont; } /* ignore the basic threshold entries -- should already be processed */ if (strcmp(defel->defname, "active_statements") == 0) goto L_loop_cont; if (strcmp(defel->defname, "max_cost") == 0) goto L_loop_cont; if (strcmp(defel->defname, "cost_overcommit") == 0) goto L_loop_cont; if (strcmp(defel->defname, "min_cost") == 0) goto L_loop_cont; if (!GetResourceTypeByName(defel->defname, &resTypeInt, &resTypeOid)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("option \"%s\" is not a valid resource type", defel->defname))); pKeyVal = makeString(defel->defname); /* WITHOUT clause value determined in pg_resourcetype */ if (!bWithout) pStrVal = makeString(defGetString(defel)); else { pStrVal = NULL; /* if NULL, delete entry from * pg_resqueuecapability */ pcqCtx = caql_beginscan( caql_addrel(cqclr(&cqc), rel), cql("SELECT * FROM pg_resourcetype" " WHERE restypid = :1 FOR UPDATE", Int16GetDatum(resTypeInt))); while (HeapTupleIsValid(tuple = caql_getnext(pcqCtx))) { text *shutoff_text = NULL; char *shutoff_str = NULL; Datum shutoff_datum; bool isnull = false; Form_pg_resourcetype rtyp = (Form_pg_resourcetype)GETSTRUCT(tuple); if (!rtyp->reshasdisable) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("option \"%s\" cannot be disabled", defel->defname))); } /* required type must have a default value if it can * be disabled */ if (!rtyp->reshasdefault) { if (!rtyp->resrequired) /* optional resource without a default is * turned off by removing entry from * pg_resqueuecapability */ break; else { /* XXX XXX */ Assert(0); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("required option \"%s\" cannot be disabled", defel->defname))); } } /* get the shutoff string */ shutoff_datum = heap_getattr(tuple, Anum_pg_resourcetype_resdisabledsetting, tupdesc, &isnull); Assert(!isnull); shutoff_text = DatumGetTextP(shutoff_datum); shutoff_str = DatumGetCString( DirectFunctionCall1( textout, PointerGetDatum(shutoff_text))); pStrVal = makeString(shutoff_str); break; } /* end while heaptuple is valid */ caql_endscan(pcqCtx); } /* check for duplicate key specifications */ if (list_member(dupcheck, pKeyVal)) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("conflicting or redundant option for \"%s\"", defel->defname))); dupcheck = lappend(dupcheck, pKeyVal); pentry = list_make2( makeInteger(resTypeInt), pStrVal); /* list of lists - (resource type, resource setting) */ if (bWithout) { /* if the "without" entry has an "off" value, then treat * it as a regular "with" item and update it in * pg_resqueuecapability, else remove its entry */ if (!pStrVal) dropelems = lappend(dropelems, pentry); else elems = lappend(elems, pentry); } else elems = lappend(elems, pentry); L_loop_cont: resTypeInt = 0; /* make compiler happy */ }
/* * Create a DefElem setting "oids" to the specified value. */ DefElem * defWithOids(bool value) { return makeDefElem("oids", (Node *) makeInteger(value)); }
/* * GetStreamScanPlan */ ForeignScan * GetStreamScanPlan(PlannerInfo *root, RelOptInfo *baserel, Oid relid, ForeignPath *best_path, List *tlist, List *scan_clauses, Plan *outer_plan) { StreamFdwInfo *sinfo = (StreamFdwInfo *) baserel->fdw_private; List *physical_tlist = build_physical_tlist(root, baserel); RangeTblEntry *rte = NULL; int i; TableSampleClause *sample; Value *sample_cutoff = NULL; /* Reduce RestrictInfo list to bare expressions; ignore pseudoconstants */ scan_clauses = extract_actual_clauses(scan_clauses, false); for (i = 1; i <= root->simple_rel_array_size; i++) { rte = root->simple_rte_array[i]; if (rte && rte->relid == relid) break; } if (!rte || rte->relid != relid) elog(ERROR, "stream RTE missing"); sample = rte->tablesample; if (sample) { double dcutoff; Datum d; ExprContext *econtext; bool isnull; Node *node; Expr *expr; ExprState *estate; ParseState *ps = make_parsestate(NULL); float4 percent; if (sample->tsmhandler != BERNOULLI_OID) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("tablesample method %s is not supported by streams", get_func_name(sample->tsmhandler)), errhint("Only bernoulli tablesample method can be used with streams."))); if (sample->repeatable) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("streams don't support the REPEATABLE clause for tablesample"))); econtext = CreateStandaloneExprContext(); ps = make_parsestate(NULL); node = (Node *) linitial(sample->args); node = transformExpr(ps, node, EXPR_KIND_OTHER); expr = expression_planner((Expr *) node); estate = ExecInitExpr(expr, NULL); d = ExecEvalExpr(estate, econtext, &isnull, NULL); free_parsestate(ps); FreeExprContext(econtext, false); percent = DatumGetFloat4(d); if (percent < 0 || percent > 100 || isnan(percent)) ereport(ERROR, (errcode(ERRCODE_INVALID_TABLESAMPLE_ARGUMENT), errmsg("sample percentage must be between 0 and 100"))); dcutoff = rint(((double) RAND_MAX + 1) * percent / 100); sample_cutoff = makeInteger((int) dcutoff); } return make_foreignscan(tlist, scan_clauses, baserel->relid, NIL, list_make3(sinfo->colnames, physical_tlist, sample_cutoff), NIL, NIL, outer_plan); }
refObject makingType(refChar name, int align, int size) { return makePair(hooks[strTypeHook], makePair(bufferToString(name), makePair(makeInteger(align), makePair(makeInteger(size), nil)))); }
void bindError(refChar string, int err) { setKey(layers, internQuotedName(string), makeIntegerType(err), makeInteger(err)); userErrs = setAdjoin(userErrs, err); }
// Bind names to simple types. bindName("char0", makePrefix(typeHook, char0Simple), char0Simple); bindName("char1", makePrefix(typeHook, char1Simple), char1Simple); bindName("int0", makePrefix(typeHook, int0Simple), int0Simple); bindName("int1", makePrefix(typeHook, int1Simple), int1Simple); bindName("int2", makePrefix(typeHook, int2Simple), int2Simple); bindName("list", makePrefix(typeHook, listSimple), listSimple); bindName("null", makePrefix(typeHook, nullSimple), nullSimple); bindName("real0", makePrefix(typeHook, real0Simple), real0Simple); bindName("real1", makePrefix(typeHook, real1Simple), real1Simple); bindName("void", makePrefix(typeHook, voidSimple), voidSimple); // Bind the name EOS to the integer end-of-stream sentinel. bindName("eos", int2Simple, makeInteger(EOF)); // We use SKIP a lot, so the variable SKIP points to it. skip = hooks[skipHook]; bindName("skip", voidSimple, skip); // Make jokers. The garbage collector must explicitly mark the ones that names // aren't bound to. (See ORSON/HUNK.) aljJoker = makeJoker("alj", altsHook); chaJoker = makeJoker("cha", char0Hook, char1Hook); exeJoker = makeJoker("exe", arrayHook, arraysHook, char0Hook, char1Hook, int0Hook, int1Hook, int2Hook, nullHook, procHook, real0Hook, real1Hook, referHook,