Exemplo n.º 1
0
TEST_F(SelectTests, simple_select_with_raw_table_equals_predicate) {
  hyrise::storage::c_atable_ptr_t t = createRawTable();

  auto expr1 = new EqualsExpressionRaw<hyrise_int_t>(t, 0, 75);
  auto scan = std::make_shared<SimpleRawTableScan>(expr1);
  scan->addInput(t);
  scan->execute();

  ASSERT_EQ(1u, scan->getResultTable(0)->size());
  const auto& out = scan->getResultTable();
  const auto& reference = Loader::shortcuts::load("test/reference/simple_raw_select_integer.tbl");
  ASSERT_TABLE_EQUAL(reference, out);
}
Exemplo n.º 2
0
TEST_F(SelectTests, simple_select_with_raw_table_equals_predicate_string) {
  auto t = createRawTable();

  auto expr1 = new EqualsExpressionRaw<hyrise_string_t>(t, 1, "MeinNameIstSlimShady75");
  auto scan = std::make_shared<SimpleRawTableScan>(expr1);
  scan->addInput(t);

  scan->execute();

  ASSERT_EQ(1u, scan->getResultTable(0)->size());
  const auto& out = scan->getResultTable();
  const auto& reference = Loader::shortcuts::load("test/reference/simple_raw_select_integer.tbl");
  ASSERT_TABLE_EQUAL(reference, out);
}
Exemplo n.º 3
0
const PlanOperation* PlanOperation::execute() {
  const bool recordPerformance = _performance_attr != nullptr;

  // Check if we really need this
  epoch_t startTime = 0;
  if (recordPerformance)
    startTime = get_epoch_nanoseconds();

  PapiTracer pt;

  // Start the execution
  refreshInput();
  setupPlanOperation();

  if (recordPerformance) {
    pt.addEvent("PAPI_TOT_CYC");
    pt.addEvent(getEvent());
    pt.start();
  }

  executePlanOperation();

  if (recordPerformance)
    pt.stop();

  teardownPlanOperation();

  if (recordPerformance) {
    epoch_t endTime = get_epoch_nanoseconds();
    std::string threadId = boost::lexical_cast<std::string>(std::this_thread::get_id());

    size_t cardinality;
    if (getResultTable() != empty_result)
      cardinality = getResultTable()->size();
    else
      // the cardinality is max(size_t) by convention if there is no return table
      cardinality = std::numeric_limits<size_t>::max();

    *_performance_attr = (performance_attributes_t) {pt.value("PAPI_TOT_CYC"), pt.value(getEvent()), getEvent(),
                                                     planOperationName(),      _operatorId,          startTime,
                                                     endTime,                  threadId,             cardinality};
  }

  setState(OpSuccess);
  return this;
}
Exemplo n.º 4
0
TEST_F(SelectTests, simple_select_with_raw_table_greater_than_predicate) {
  auto t = createRawTable();

  auto expr1 = new GreaterThanExpressionRaw<hyrise_int_t>(t, 0, 98);
  auto scan = std::make_shared<SimpleRawTableScan>(expr1);
  scan->addInput(t);

  scan->execute();
  const auto& out = scan->getResultTable();
  const auto& reference = Loader::shortcuts::load("test/reference/simple_raw_select_integer_greater_than.tbl");
  ASSERT_TABLE_EQUAL(reference, out);
}
Exemplo n.º 5
0
TEST_F(LayouterOpsTest, simple_parse_json) {
  std::string data = loadFromFile("test/json/simple_layouter.json");
  Json::Value request_data;
  Json::Reader reader;

  // Parse JSON
  reader.parse(data, request_data);

  // parse the json
  auto s = std::dynamic_pointer_cast<LayoutSingleTable>(LayoutSingleTable::parse(request_data["operators"]["0"]));
  s->executePlanOperation();
  const auto& res = s->getResultTable();
  std::string header = loadFromFile("test/header/layouter_simple.tbl");

  ASSERT_EQ(res->getValue<std::string>(0, 0), header);
}
Exemplo n.º 6
0
TEST_F(JSONTests, parse_projection) {
  hyrise::storage::atable_ptr_t t = Loader::shortcuts::load("test/lin_xxs.tbl");
  hyrise::storage::atable_ptr_t reference = Loader::shortcuts::load("test/reference/simple_projection.tbl");
  std::string query = "{\"type\": \"ProjectionScan\", \"fields\": [0], \"inputs\": [\"table1\"] }";

  Json::Value root;
  Json::Reader reader;
  bool parsingSuccessful = reader.parse(query , root);

  ASSERT_TRUE(parsingSuccessful);

  // Create the Plan Op

  auto ps = std::dynamic_pointer_cast<_PlanOperation>(QueryParser::instance().parse("ProjectionScan", root));
  ps->addInput(t);
  ps->execute();
  ASSERT_EQ(OpSuccess, ps->getState());
  auto result = ps->getResultTable();
  ASSERT_TRUE(result->contentEquals(reference));

}
Exemplo n.º 7
0
Json::Value ResponseTask::generateResponseJson() {
  Json::Value response;
  epoch_t responseStart = _recordPerformanceData ? get_epoch_nanoseconds() : 0;
  PapiTracer pt;
  pt.addEvent("PAPI_TOT_CYC");

  if (_recordPerformanceData)
    pt.start();

  auto predecessor = getResultTask();
  const auto& result = predecessor->getResultTable();

  if (getState() != OpFail) {
    if (!_isAutoCommit) {
      response["session_context"] =
          std::to_string(_txContext.tid).append(" ").append(std::to_string(_txContext.lastCid));
    }

    if (result) {
      // Make header
      Json::Value json_header(Json::arrayValue);
      for (unsigned col = 0; col < result->columnCount(); ++col) {
        Json::Value colname(result->nameOfColumn(col));
        json_header.append(colname);
      }

      // Copy the complete result
      response["real_size"] = result->size();
      response["rows"] = generateRowsJson(result, _transmitLimit, _transmitOffset);
      response["header"] = json_header;
    }

    ////////////////////////////////////////////////////////////////////////////////////////
    // Copy Performance Data
    if (_recordPerformanceData) {
      Json::Value json_perf(Json::arrayValue);
      for (const auto& attr : performance_data) {
        Json::Value element;
        element["papi_event"] = Json::Value(attr->papiEvent);
        element["duration"] = Json::Value((Json::UInt64)attr->duration);
        element["data"] = Json::Value((Json::UInt64)attr->data);
        element["name"] = Json::Value(attr->name);
        element["id"] = Json::Value(attr->operatorId);
        element["startTime"] = Json::Value((double)(attr->startTime - queryStart) / 1000000);
        element["endTime"] = Json::Value((double)(attr->endTime - queryStart) / 1000000);
        element["executingThread"] = Json::Value(attr->executingThread);
        element["lastCore"] = Json::Value(attr->core);
        element["lastNode"] = Json::Value(attr->node);
        // Put null for in/outRows if -1 was set
        element["inRows"] = attr->in_rows ? Json::Value(*(attr->in_rows)) : Json::Value();
        element["outRows"] = attr->out_rows ? Json::Value(*(attr->out_rows)) : Json::Value();

        if (_getSubQueryPerformanceData) {
          element["subQueryPerformanceData"] = _scriptOperation->getSubQueryPerformanceData();
        }

        json_perf.append(element);
      }

      pt.stop();

      Json::Value responseElement;
      responseElement["duration"] = Json::Value((Json::UInt64)pt.value("PAPI_TOT_CYC"));
      responseElement["name"] = Json::Value("ResponseTask");
      responseElement["id"] = Json::Value("respond");
      responseElement["startTime"] = Json::Value((double)(responseStart - queryStart) / 1000000);
      responseElement["endTime"] = Json::Value((double)(get_epoch_nanoseconds() - queryStart) / 1000000);

      std::string threadId = boost::lexical_cast<std::string>(std::this_thread::get_id());
      responseElement["executingThread"] = Json::Value(threadId);

      responseElement["lastCore"] = Json::Value(getCurrentCore());
      responseElement["lastNode"] = Json::Value(getCurrentNode());

      std::optional<size_t> result_size;
      if (result) {
        result_size = result->size();
      }
      responseElement["inRows"] = result_size ? Json::Value(*result_size) : Json::Value();
      responseElement["outRows"] = Json::Value();

      json_perf.append(responseElement);

      response["performanceData"] = json_perf;
    }

    Json::Value jsonKeys(Json::arrayValue);
    for (const auto& x : _generatedKeyRefs) {
      for (const auto& key : *x) {
        Json::Value element(key);
        jsonKeys.append(element);
      }
    }
    response["generatedKeys"] = jsonKeys;
    response["affectedRows"] = Json::Value(_affectedRows);

    if (_getSubQueryPerformanceData) {
      response["subQueryDataflow"] = _scriptOperation->getSubQueryDataflow();
    }
  }
  LOG4CXX_DEBUG(_logger, "Table Use Count: " << result.use_count());

  return response;
}
Exemplo n.º 8
0
void ResponseTask::operator()() {
  epoch_t responseStart = get_epoch_nanoseconds();
  Json::Value response;

  if (getDependencyCount() > 0) {
    PapiTracer pt;
    pt.addEvent("PAPI_TOT_CYC");
    pt.start();

    auto predecessor = getResultTask();
    const auto& result = predecessor->getResultTable();

    if (predecessor->getState() != OpFail) {
      if (result) {
        // Make header
        Json::Value json_header(Json::arrayValue);
        for (unsigned col = 0; col < result->columnCount(); ++col) {
          Json::Value colname(result->nameOfColumn(col));
          json_header.append(colname);
        }

        // Copy the complete result
        response["real_size"] = result->size();
        response["rows"] = generateRowsJson(result, _transmitLimit);
        response["header"] = json_header;
      }

      // Copy Performance Data
      Json::Value json_perf(Json::arrayValue);
      for (const auto & attr: performance_data) {
        Json::Value element;
        element["papi_event"] = Json::Value(attr->papiEvent);
        element["duration"] = Json::Value((Json::UInt64) attr->duration);
        element["data"] = Json::Value((Json::UInt64) attr->data);
        element["name"] = Json::Value(attr->name);
        element["id"] = Json::Value(attr->operatorId);
        element["startTime"] = Json::Value((double)(attr->startTime - queryStart) / 1000000);
        element["endTime"] = Json::Value((double)(attr->endTime - queryStart) / 1000000);
        element["executingThread"] = Json::Value(attr->executingThread);
        json_perf.append(element);
      }
      pt.stop();

      Json::Value responseElement;
      responseElement["duration"] = Json::Value((Json::UInt64) pt.value("PAPI_TOT_CYC"));
      responseElement["name"] = Json::Value("ResponseTask");
      responseElement["id"] = Json::Value("respond");
      responseElement["startTime"] = Json::Value((double)(responseStart - queryStart) / 1000000);
      responseElement["endTime"] = Json::Value((double)(get_epoch_nanoseconds() - queryStart) / 1000000);

      std::string threadId = boost::lexical_cast<std::string>(std::this_thread::get_id());
      responseElement["executingThread"] = Json::Value(threadId);
      json_perf.append(responseElement);

      response["performanceData"] = json_perf;
    } else {
      LOG4CXX_ERROR(_logger, "Error during plan execution: " << predecessor->getErrorMessage());
      response["error"] = predecessor->getErrorMessage();
    }
    LOG4CXX_DEBUG(_logger, "Table Use Count: " << result.use_count());
  } else {
    response["error"] = "Query parsing failed, see server error log";
  }

  connection->respond(response.toStyledString());
}