本文整理汇总了C++中AbstractExpression类的典型用法代码示例。如果您正苦于以下问题:C++ AbstractExpression类的具体用法?C++ AbstractExpression怎么用?C++ AbstractExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbstractExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
bool DistinctExecutor::p_execute(const NValueArray ¶ms) {
DistinctPlanNode* node = dynamic_cast<DistinctPlanNode*>(m_abstractNode);
assert(node);
Table* output_table = node->getOutputTable();
assert(output_table);
Table* input_table = node->getInputTables()[0];
assert(input_table);
TableIterator iterator = input_table->iterator();
TableTuple tuple(input_table->schema());
// substitute params for distinct expression
AbstractExpression *distinctExpression = node->getDistinctExpression();
distinctExpression->substitute(params);
std::set<NValue, NValue::ltNValue> found_values;
while (iterator.next(tuple)) {
//
// Check whether this value already exists in our list
//
NValue tuple_value = distinctExpression->eval(&tuple, NULL);
if (found_values.find(tuple_value) == found_values.end()) {
found_values.insert(tuple_value);
if (!output_table->insertTuple(tuple)) {
VOLT_ERROR("Failed to insert tuple from input table '%s' into"
" output table '%s'",
input_table->name().c_str(),
output_table->name().c_str());
return false;
}
}
}
return true;
}
示例2: operator
bool operator()(TableTuple ta, TableTuple tb)
{
for (size_t i = 0; i < m_keyCount; ++i)
{
AbstractExpression* k = m_keys[i];
SortDirectionType dir = m_dirs[i];
int cmp = k->eval(&ta, NULL).compare(k->eval(&tb, NULL));
if (dir == SORT_DIRECTION_TYPE_ASC)
{
if (cmp < 0) return true;
if (cmp > 0) return false;
}
else if (dir == SORT_DIRECTION_TYPE_DESC)
{
if (cmp < 0) return false;
if (cmp > 0) return true;
}
else
{
throw SerializableEEException(VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION,
"Attempted to sort using"
" SORT_DIRECTION_TYPE_INVALID");
}
}
return false; // ta == tb on these keys
}
示例3: columnAllowNull
TupleSchema* AbstractPlanNode::generateTupleSchema(const std::vector<SchemaColumn*>& outputSchema)
{
int schema_size = static_cast<int>(outputSchema.size());
vector<voltdb::ValueType> columnTypes;
vector<int32_t> columnSizes;
vector<bool> columnAllowNull(schema_size, true);
vector<bool> columnInBytes;
for (int i = 0; i < schema_size; i++)
{
//TODO: SchemaColumn is a sad little class that holds an expression pointer,
// a column name that only really comes in handy in one quirky special case,
// (see UpdateExecutor::p_init) and a bunch of other stuff that doesn't get used.
// Someone should put that class out of our misery.
SchemaColumn* col = outputSchema[i];
AbstractExpression * expr = col->getExpression();
columnTypes.push_back(expr->getValueType());
columnSizes.push_back(expr->getValueSize());
columnInBytes.push_back(expr->getInBytes());
}
TupleSchema* schema =
TupleSchema::createTupleSchema(columnTypes, columnSizes,
columnAllowNull, columnInBytes);
return schema;
}
示例4: test_interpreter
void test_interpreter()
{
ContextInterpreter* pContext = new ContextInterpreter();
AbstractExpression* pTe = new TerminalExpression("hello world");
AbstractExpression* pNte = new NonterminalExpression(pTe, 3);
pNte->Interpreter(*pContext);
}
示例5: main
int main(int argc,char* argv[]) {
Context* c = new Context();
AbstractExpression* te = new TerminalExpression("hello");
AbstractExpression* nte = new NonterminalExpression(te,2);
nte->Interpret(*c);
delete nte;
delete c;
return 0;
}
示例6:
AbstractExpression *AbstractExpression::CreateExpressionTree(
json_spirit::Object &obj) {
AbstractExpression *expr =
AbstractExpression::CreateExpressionTreeRecurse(obj);
if (expr) expr->InitParamShortCircuits();
return expr;
}
示例7: assert
bool MaterializedScanExecutor::p_execute(const NValueArray ¶ms) {
MaterializedScanPlanNode* node = dynamic_cast<MaterializedScanPlanNode*>(m_abstractNode);
assert(node);
// output table has one column
Table* output_table = node->getOutputTable();
TableTuple& tmptup = output_table->tempTuple();
assert(output_table);
assert ((int)output_table->columnCount() == 1);
// get the output type
const TupleSchema::ColumnInfo *columnInfo = output_table->schema()->getColumnInfo(0);
ValueType outputType = columnInfo->getVoltType();
bool outputCantBeNull = !columnInfo->allowNull;
AbstractExpression* rowsExpression = node->getTableRowsExpression();
assert(rowsExpression);
// get array nvalue
NValue arrayNValue = rowsExpression->eval();
SortDirectionType sort_direction = node->getSortDirection();
// make a set to eliminate unique values in O(nlogn) time
std::vector<NValue> sortedUniques;
// iterate over the array of values and build a sorted/deduped set of
// values that don't overflow or violate unique constaints
arrayNValue.castAndSortAndDedupArrayForInList(outputType, sortedUniques);
// insert all items in the set in order
if (sort_direction != SORT_DIRECTION_TYPE_DESC) {
std::vector<NValue>::const_iterator iter;
for (iter = sortedUniques.begin(); iter != sortedUniques.end(); iter++) {
if ((*iter).isNull() && outputCantBeNull) {
continue;
}
tmptup.setNValue(0, *iter);
output_table->insertTuple(tmptup);
}
} else {
std::vector<NValue>::reverse_iterator reverse_iter;
for (reverse_iter = sortedUniques.rbegin(); reverse_iter != sortedUniques.rend(); reverse_iter++) {
if ((*reverse_iter).isNull() && outputCantBeNull) {
continue;
}
tmptup.setNValue(0, *reverse_iter);
output_table->insertTuple(tmptup);
}
}
VOLT_TRACE("\n%s\n", output_table->debug().c_str());
VOLT_DEBUG("Finished Materializing a Table");
return true;
}
示例8: TEST_F
TEST_F(FilterTest, ComplexFilter) {
// WHERE val1=1 AND val2=2 AND val3=3 AND val4=4
// shared_ptr<AbstractExpression> equal1
// = ComparisonExpression::getInstance(EXPRESSION_TYPE_COMPARE_EQUAL, TupleValueExpression::getInstance(1), ConstantValueExpression::getInstance(voltdb::Value::newBigIntValue(1)));
// shared_ptr<AbstractExpression> equal2
// = ComparisonExpression::getInstance(EXPRESSION_TYPE_COMPARE_EQUAL, TupleValueExpression::getInstance(2), ConstantValueExpression::getInstance(voltdb::Value::newBigIntValue(2)));
// shared_ptr<AbstractExpression> equal3
// = ComparisonExpression::getInstance(EXPRESSION_TYPE_COMPARE_EQUAL, TupleValueExpression::getInstance(3), ConstantValueExpression::getInstance(voltdb::Value::newBigIntValue(3)));
// shared_ptr<AbstractExpression> equal4
// = ComparisonExpression::getInstance(EXPRESSION_TYPE_COMPARE_EQUAL, TupleValueExpression::getInstance(4), ConstantValueExpression::getInstance(voltdb::Value::newBigIntValue(4)));
//
// shared_ptr<AbstractExpression> predicate3
// = ConjunctionExpression::getInstance(EXPRESSION_TYPE_CONJUNCTION_AND, equal3, equal4);
// shared_ptr<AbstractExpression> predicate2
// = ConjunctionExpression::getInstance(EXPRESSION_TYPE_CONJUNCTION_AND, equal2, predicate3);
//
// ConjunctionExpression predicate(EXPRESSION_TYPE_CONJUNCTION_AND, equal1, predicate2);
AbstractExpression *equal1 = comparisonFactory(EXPRESSION_TYPE_COMPARE_EQUAL,
new TupleValueExpression(1, std::string("tablename"), std::string("colname")),
constantValueFactory(ValueFactory::getBigIntValue(1)));
AbstractExpression *equal2 = comparisonFactory(EXPRESSION_TYPE_COMPARE_EQUAL,
new TupleValueExpression(2, std::string("tablename"), std::string("colname")),
constantValueFactory(ValueFactory::getBigIntValue(2)));
AbstractExpression *equal3 = comparisonFactory(EXPRESSION_TYPE_COMPARE_EQUAL,
new TupleValueExpression(3, std::string("tablename"), std::string("colname")),
constantValueFactory(ValueFactory::getBigIntValue(3)));
AbstractExpression *equal4 = comparisonFactory(EXPRESSION_TYPE_COMPARE_EQUAL,
new TupleValueExpression(4, std::string("tablename"), std::string("colname")),
constantValueFactory(ValueFactory::getBigIntValue(4)));
AbstractExpression *predicate3 = conjunctionFactory(EXPRESSION_TYPE_CONJUNCTION_AND, equal3, equal4);
AbstractExpression *predicate2 = conjunctionFactory(EXPRESSION_TYPE_CONJUNCTION_AND, equal2, predicate3);
AbstractExpression *predicate = conjunctionFactory(EXPRESSION_TYPE_CONJUNCTION_AND, equal1, predicate2);
// ::printf("\nFilter:%s\n", predicate->debug().c_str());
int count = 0;
TableIterator iter = table->iterator();
TableTuple match(table->schema());
while (iter.next(match)) {
if (predicate->eval(&match, NULL).isTrue()) {
//::printf(" match:%s\n", match->debug(table).c_str());
++count;
}
}
ASSERT_EQ(5, count);
delete predicate;
}
示例9:
// ------------------------------------------------------------------
// SERIALIZATION METHODS
// ------------------------------------------------------------------
AbstractExpression*
AbstractExpression::buildExpressionTree(json_spirit::Object &obj)
{
AbstractExpression * exp =
AbstractExpression::buildExpressionTree_recurse(obj);
if (exp)
exp->initParamShortCircuits();
return exp;
}
示例10:
// ------------------------------------------------------------------
// SERIALIZATION METHODS
// ------------------------------------------------------------------
AbstractExpression*
AbstractExpression::buildExpressionTree(PlannerDomValue obj)
{
AbstractExpression * exp =
AbstractExpression::buildExpressionTree_recurse(obj);
if (exp)
exp->initParamShortCircuits();
return exp;
}
示例11: main
int main()
{
Context* con1 = new Context("Hello world.");
AbstractExpression* tinter = new TerminalExpression();
AbstractExpression* nont = new NonTerminalExpression();
tinter->Interpreter(con1);
nont->Interpreter(con1);
return 0;
}
示例12:
bool AbstractExecutor::TupleComparer::operator()(TableTuple ta, TableTuple tb) const
{
for (size_t i = 0; i < m_keyCount; ++i)
{
AbstractExpression* k = m_keys[i];
SortDirectionType dir = m_dirs[i];
int cmp = k->eval(&ta, NULL).compare(k->eval(&tb, NULL));
if (cmp < 0) return (dir == SORT_DIRECTION_TYPE_ASC);
if (cmp > 0) return (dir == SORT_DIRECTION_TYPE_DESC);
}
return false; // ta == tb on these keys
}
示例13: VOLT_TRACE
/*
*
* Helper method responsible for inserting the results of the
* aggregation into a new tuple in the output table as well as passing
* through any additional columns from the input table.
*/
inline void WindowFunctionExecutor::insertOutputTuple()
{
TableTuple& tempTuple = m_tmpOutputTable->tempTuple();
// We copy the aggregate values into the output tuple,
// then the passthrough columns.
WindowAggregate** aggs = m_aggregateRow->getAggregates();
for (int ii = 0; ii < getAggregateCount(); ii++) {
NValue result = aggs[ii]->finalize(tempTuple.getSchema()->columnType(ii));
tempTuple.setNValue(ii, result);
}
VOLT_TRACE("Setting passthrough columns");
size_t tupleSize = tempTuple.sizeInValues();
for (int ii = getAggregateCount(); ii < tupleSize; ii += 1) {
AbstractExpression *expr = m_outputColumnExpressions[ii];
tempTuple.setNValue(ii, expr->eval(&(m_aggregateRow->getPassThroughTuple())));
}
m_tmpOutputTable->insertTempTuple(tempTuple);
VOLT_TRACE("output_table:\n%s", m_tmpOutputTable->debug().c_str());
}
示例14: main
int main(int argc, char* argv[])
{
//生成表达式
AbstractExpression* expression;
//解析器对象
Context context;
//两个变量
VariableExp* varX = new VariableExp("keyX");
VariableExp* varY = new VariableExp("keyY");
/*一个复杂表达式 或(与(常量,变量),与(变量,非(变量)))*/
expression = new OrExp(
new AndExp(new ConstantExp(true), varX),
new AndExp(varY, new NotExp(varX)));
//在解析器中建立外部名字和值的关联
context.Assign(varX, false);
context.Assign(varY, true);
//递归运算表达式求值
bool result = expression->Interpret(context);
cout<<"result: "<<result<<endl;
printf("Hello World!\n");
return 0;
}
示例15: Expression
Expression(const AbstractExpression& expr) : pointer(expr.Clone()) { }