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;
}
Пример #2
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;
}
Пример #3
0
hashcode_t HashCode::hashcodeByUnRepeatedField(const Message* msg, const FieldDescriptor* field) {
  auto reflect = msg->GetReflection();
  switch (field->cpp_type()) {
  case FieldDescriptor::CPPTYPE_UINT64:
    return stl_hashcode(reflect->GetUInt64(*msg, field));
  case FieldDescriptor::CPPTYPE_INT64:
    return stl_hashcode(reflect->GetInt64(*msg, field));
  case FieldDescriptor::CPPTYPE_UINT32:
    return stl_hashcode(reflect->GetUInt32(*msg, field));
  case FieldDescriptor::CPPTYPE_INT32:
    return stl_hashcode(reflect->GetInt32(*msg, field));
  case FieldDescriptor::CPPTYPE_STRING:
    return stl_hashcode(reflect->GetString(*msg, field));
  case FieldDescriptor::CPPTYPE_DOUBLE:
    return stl_hashcode(reflect->GetDouble(*msg, field));
  case FieldDescriptor::CPPTYPE_FLOAT:
    return stl_hashcode(reflect->GetFloat(*msg, field));
  case FieldDescriptor::CPPTYPE_BOOL:
    return stl_hashcode(reflect->GetBool(*msg, field));
  case FieldDescriptor::CPPTYPE_ENUM:
    return stl_hashcode(reflect->GetEnum(*msg, field)->number());
  case FieldDescriptor::CPPTYPE_MESSAGE:
    return stl_hashcode(reflect->GetMessage(*msg, field));
  default:
    LOG(ERROR)<< "The type of protobuf is not supported";
    return 0;
  }
}
Пример #4
0
int64_t
JsValue::GetInt64() const
{
    std::string whyNot;
    if (not _CheckType(_holder->type, IntType, &whyNot)) {
        TF_CODING_ERROR(whyNot);
        return 0;
    }

    if (IsUInt64())
        return static_cast<int64_t>(GetUInt64());

    return boost::get<int64_t>(_holder->value);
}
Пример #5
0
double
JsValue::GetReal() const
{
    if (_holder->type == IntType) {
        return IsUInt64() ?
            static_cast<double>(GetUInt64()) :
            static_cast<double>(GetInt64());
    }

    std::string whyNot;
    if (not _CheckType(_holder->type, RealType, &whyNot)) {
        TF_CODING_ERROR(whyNot);
        return 0;
    }

    return boost::get<double>(_holder->value);
}
    Value *GetDefaultValue(CodeGenerator *codegen, AstTypeNode *typeNode) {
        switch (typeNode->getTypeType()) {
        default: return nullptr;
        case node_boolean: return codegen->getBuilder().getFalse();
        case node_float: return GetFloat(codegen, 0.0f);
        case node_double: return GetDouble(codegen, 0.0);

        case node_signed_integer8: return GetInt8(codegen, 0);
        case node_signed_integer16: return GetInt16(codegen, 0);
        case node_signed_integer32: return GetInt32(codegen, 0);
        case node_signed_integer64: return GetInt64(codegen, 0);

        case node_unsigned_integer8: return GetUInt8(codegen, 0);
        case node_unsigned_integer16: return GetUInt16(codegen, 0);
        case node_unsigned_integer32: return GetUInt32(codegen, 0);
        case node_unsigned_integer64: return GetUInt64(codegen, 0);

        case node_string: return GetString(codegen, "");
        }
    }
Пример #7
0
void CMdbResult::GetNumber(void* v, register uint32 nFieldNo)
{
	switch(GetType(nFieldNo))
	{
	case MDB_INT8_FIELD:
		*(int8*)v = GetInt8(nFieldNo);
		break;
	case MDB_INT16_FIELD:
		*(int16*)v = GetInt16(nFieldNo);
		break;
	case MDB_INT32_FIELD:
		*(int32*)v = GetInt32(nFieldNo);
		break;
	case MDB_INT64_FIELD:
		*(int64*)v = GetInt64(nFieldNo);
		break;
	case MDB_UINT8_FIELD:
		*(uint8*)v = GetUInt8(nFieldNo);
		break;
	case MDB_UINT16_FIELD:
		*(uint16*)v = GetUInt16(nFieldNo);
		break;
	case MDB_UINT32_FIELD:
		*(uint32*)v = GetUInt32(nFieldNo);
		break;
	case MDB_UINT64_FIELD:
		*(uint64*)v = GetUInt64(nFieldNo);
		break;
	case MDB_FLOAT_FIELD:
		*(float*)v = GetFloat(nFieldNo);
		break;
	case MDB_DOUBLE_FIELD:
	case MDB_DATETIME_FIELD:
		*(double*)v = GetDouble(nFieldNo);
		break;
	case MDB_DATE_FIELD:
	case MDB_TIME_FIELD:
		*(int32*)v = GetInt32(nFieldNo);
		break;
	}
}
Пример #8
0
void Pb2Json::Message2Json(const ProtobufMsg& message, Json& json, bool enum2str) {
    auto descriptor = message.GetDescriptor();
    auto reflection = message.GetReflection();
    if (nullptr == descriptor || nullptr == descriptor) return;

    auto count = descriptor->field_count();

    for (auto i = 0; i < count; ++i) {
        const auto field = descriptor->field(i);

        if (field->is_repeated()) {
            if (reflection->FieldSize(message, field) > 0)
                RepeatedMessage2Json(message, field, reflection, json[field->name()], enum2str);

            continue;
        }

        if (!reflection->HasField(message, field)) {
            continue;
        }

        switch (field->type()) {
            case ProtobufFieldDescriptor::TYPE_MESSAGE: {
                const ProtobufMsg& tmp_message = reflection->GetMessage(message, field);
                if (0 != tmp_message.ByteSize()) Message2Json(tmp_message, json[field->name()]);
            } break;

            case ProtobufFieldDescriptor::TYPE_BOOL:
                json[field->name()] = reflection->GetBool(message, field) ? true : false;
                break;

            case ProtobufFieldDescriptor::TYPE_ENUM: {
                auto* enum_value_desc = reflection->GetEnum(message, field);
                if (enum2str) {
                    json[field->name()] = enum_value_desc->name();
                } else {
                    json[field->name()] = enum_value_desc->number();
                }
            } break;

            case ProtobufFieldDescriptor::TYPE_INT32:
            case ProtobufFieldDescriptor::TYPE_SINT32:
            case ProtobufFieldDescriptor::TYPE_SFIXED32:
                json[field->name()] = reflection->GetInt32(message, field);
                break;

            case ProtobufFieldDescriptor::TYPE_UINT32:
            case ProtobufFieldDescriptor::TYPE_FIXED32:
                json[field->name()] = reflection->GetUInt32(message, field);
                break;

            case ProtobufFieldDescriptor::TYPE_INT64:
            case ProtobufFieldDescriptor::TYPE_SINT64:
            case ProtobufFieldDescriptor::TYPE_SFIXED64:
                json[field->name()] = reflection->GetInt64(message, field);
                break;

            case ProtobufFieldDescriptor::TYPE_UINT64:
            case ProtobufFieldDescriptor::TYPE_FIXED64:
                json[field->name()] = reflection->GetUInt64(message, field);
                break;

            case ProtobufFieldDescriptor::TYPE_FLOAT:
                json[field->name()] = reflection->GetFloat(message, field);
                break;

            case ProtobufFieldDescriptor::TYPE_STRING:
            case ProtobufFieldDescriptor::TYPE_BYTES:
                json[field->name()] = reflection->GetString(message, field);
                break;

            default:
                break;
        }
    }
}
Пример #9
0
template <> unsigned long long Variant::Get<unsigned long long>() const
{
    return GetUInt64();
}