Exemplo n.º 1
0
TEST(SchemaTest, BasicDescriptorSerialization) {
  std::stringstream ss;

  // This step is the only step that's required to dump a full schema in proto1
  // format.  The rest of this function is just to parse it
  leap::Serialize<leap::protobuf_v1>(ss, Person::GetDescriptor());
  
  // Now we have to parse the protobuf file
  const google::protobuf::FileDescriptor* fd;
  CountsErrors error_collector;
  MemorySourceTree mst{
    { "root.proto", ss.str() }
  };

  // Importer utility class does most of the work for us, we just need to tell it
  // how to find files and where to report issues
  cl::Importer imp{ &mst, &error_collector };
  fd = imp.Import("root.proto");
  ASSERT_NE(nullptr, fd) << error_collector;

  // This part verifies that the regenerated schema is correct.
  auto personDesc = fd->FindMessageTypeByName("Person");
  ASSERT_NE(nullptr, personDesc) << "Failed to find person message in schema";
  ASSERT_NE(nullptr, personDesc->FindFieldByName("name"));
  ASSERT_NE(nullptr, personDesc->FindFieldByName("id"));
  ASSERT_NE(nullptr, personDesc->FindFieldByName("email"));
  ASSERT_NE(nullptr, personDesc->FindFieldByName("phone"));
  ASSERT_NE(nullptr, personDesc->FindFieldByName("pets"));
}
Exemplo n.º 2
0
//----------------------------------------
void CProductErs::AddInternalHighResolutionFieldCalculation()
{
  string internalFieldName;
  CField* fieldTest = NULL;

//  internalFieldName = MakeInternalFieldName(m_latitudeFieldName);
//  m_listInternalFieldName.InsertUnique( internalFieldName );
//  m_fieldNameEquivalence.Insert(m_latitudeFieldName, internalFieldName, false);
  
  fieldTest = FindFieldByName(m_latitudeFieldName, false, NULL, false);
  if (fieldTest != NULL)
  {
    internalFieldName = MakeInternalNameByAddingRoot(fieldTest->GetFullNameWithRecord());
    m_listInternalFieldName.InsertUnique( internalFieldName );
    m_fieldNameEquivalence.Insert(m_latitudeFieldName, internalFieldName, false);
  }

//  internalFieldName = MakeInternalFieldName(m_longitudeFieldName);
//  m_listInternalFieldName.InsertUnique( internalFieldName );
//  m_fieldNameEquivalence.Insert(m_longitudeFieldName, internalFieldName, false);

  fieldTest = FindFieldByName(m_longitudeFieldName, false, NULL, false);
  if (fieldTest != NULL)
  {
    internalFieldName = MakeInternalNameByAddingRoot(fieldTest->GetFullNameWithRecord());
    m_listInternalFieldName.InsertUnique( internalFieldName );
    m_fieldNameEquivalence.Insert(m_longitudeFieldName, internalFieldName, false);
  }

//  internalFieldName = MakeInternalFieldName(m_timeStampSecondFieldName);
//  m_listInternalFieldName.InsertUnique( internalFieldName );
//  m_fieldNameEquivalence.Insert(m_timeStampSecondFieldName, internalFieldName, false);

  fieldTest = FindFieldByName(m_timeStampSecondFieldName, false, NULL, false);
  if (fieldTest != NULL)
  {
    internalFieldName = MakeInternalNameByAddingRoot(fieldTest->GetFullNameWithRecord());
    m_listInternalFieldName.InsertUnique( internalFieldName );
    m_fieldNameEquivalence.Insert(m_timeStampSecondFieldName, internalFieldName, false);
  }


//  internalFieldName = MakeInternalFieldName(m_timeStampMicrosecondFieldName);
//  m_listInternalFieldName.InsertUnique( internalFieldName );
//  m_fieldNameEquivalence.Insert(m_timeStampMicrosecondFieldName, internalFieldName, false);
  
  fieldTest = FindFieldByName(m_timeStampMicrosecondFieldName, false, NULL, false);
  if (fieldTest != NULL)
  {
    internalFieldName = MakeInternalNameByAddingRoot(fieldTest->GetFullNameWithRecord());
    m_listInternalFieldName.InsertUnique( internalFieldName );
    m_fieldNameEquivalence.Insert(m_timeStampMicrosecondFieldName, internalFieldName, false);
  }


}
RddResultCode SsbQ1_1Transformer::transform(TransformerContext* ctx, const BaseRddPartition* input, PairRddPartition* output) {
  auto param = ctx->getParamRdds().at(0);
  if (input->empty() || param->empty()) {
    return RRC_SUCCESS;
  }

  auto op = ctx->getRddOperator();
  auto paramOp = op->paramOperators.at(0);
  auto exprCtx = ctx->getExpressionContext();

  auto keyTemplate = param->getKeyTemplate();
  auto valueTemplate = param->getValueTemplate();
  auto dateDes = keyTemplate->GetDescriptor();
  auto dateRef = keyTemplate->GetReflection();
  auto dateField = dateDes->FindFieldByName("d_datekey");

  set<uint64_t> marchedDate;

  param->foreach([&marchedDate, paramOp, &exprCtx, dateRef, dateField] (const PbMessagePtr& key, const PbMessagePtr& value) {
    idgs::actor::PbMessagePtr outkey, outvalue;
    exprCtx->setKeyValue(&key, &value);
    exprCtx->setOutputKeyValue(&outkey, &outvalue);

    if (paramOp->evaluate(exprCtx)) {
      marchedDate.insert(dateRef->GetUInt64(* key, dateField));
    }
  });

  valueTemplate = input->getValueTemplate();
  auto orderDes = valueTemplate->GetDescriptor();
  auto orderRef = valueTemplate->GetReflection();
  auto orderDateField = orderDes->FindFieldByName("lo_orderdate");

  input->foreach([marchedDate, output, op, &exprCtx, orderRef, orderDateField] (const PbMessagePtr& key, const PbMessagePtr& value) {
    idgs::actor::PbMessagePtr outkey, outvalue;
    exprCtx->setKeyValue(&key, &value);
    exprCtx->setOutputKeyValue(&outkey, &outvalue);

    if (op->evaluate(exprCtx)) {
      uint64_t orderdate = orderRef->GetUInt64(* value, orderDateField);

      if(marchedDate.find(orderdate) != marchedDate.end()) {
        output->put(key, value);
      }
    }
  });

  return RRC_SUCCESS;
}
Exemplo n.º 4
0
RddResultCode SsbQ1_1Transformer::transform(const ActorMessagePtr& msg, const std::vector<BaseRddPartition*>& input,
    RddPartition* output) {
  if (input.size() != 2) {
    return RRC_INVALID_RDD_INPUT;
  }

  if (input[0]->empty() || input[1]->empty()) {
    return RRC_SUCCESS;
  }

  auto orderExp = output->getFilterExpression(0);
  auto dateExp = output->getFilterExpression(1);

  auto valueTemplate = input[0]->getValueTemplate();
  auto orderDes = valueTemplate->GetDescriptor();
  auto orderRef = valueTemplate->GetReflection();
  auto orderDateField = orderDes->FindFieldByName("lo_orderdate");

  auto keyTemplate = input[1]->getKeyTemplate();
  valueTemplate = input[1]->getValueTemplate();
  auto dateDes = keyTemplate->GetDescriptor();
  auto dateRef = keyTemplate->GetReflection();
  auto dateField = dateDes->FindFieldByName("d_datekey");

  set<uint64_t> marchedDate;
  ExpressionContext ctx;
  input[1]->foreach(
      [&marchedDate, dateExp, dateRef, dateField, &ctx] (const PbMessagePtr& key, const PbMessagePtr& value) {
        ctx.setKeyValue(&key, &value);
        if ((bool) dateExp->evaluate(&ctx)) {
          marchedDate.insert(dateRef->GetUInt64(*key, dateField));
        }
      });

  input[0]->foreach(
      [marchedDate, output, orderExp, orderRef, orderDateField, dateRef, dateField, &ctx] (const PbMessagePtr& key, const PbMessagePtr& value) {
        ctx.setKeyValue(&key, &value);
        if ((bool) orderExp->evaluate(&ctx)) {
          uint64_t orderdate = orderRef->GetUInt64(* value, orderDateField);

          if(marchedDate.find(orderdate) != marchedDate.end()) {
            output->putLocal(key, value);
          }
        }
      });

  return RRC_SUCCESS;
}
Exemplo n.º 5
0
int QProtobufModel::rowCount(const QModelIndex &_index) const
{
    PBMessage* msg = getMessage(_index);

    if (msg == m_rootItem)
        return 1;

    PBMessage* parent = getMessage(_index.parent());

    auto descr = parent->GetDescriptor();

    auto field = descr->FindFieldByName(msg->GetTypeName());

    if (field->is_repeated())
    {
        int count = parent->GetReflection()->FieldSize(*parent, field);
        return count;
    }
    else
        return 1;
}