mkql_now.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "mkql_now.h"
  2. #include <yql/essentials/minikql/computation/mkql_computation_node_holders.h>
  3. #include <yql/essentials/minikql/mkql_node_cast.h>
  4. namespace NKikimr {
  5. namespace NMiniKQL {
  6. namespace {
  7. class TNowWrapper : public TMutableComputationNode<TNowWrapper> {
  8. typedef TMutableComputationNode<TNowWrapper> TBaseComputation;
  9. public:
  10. TNowWrapper(TComputationMutables& mutables, TComputationNodePtrVector&& dependentNodes)
  11. : TBaseComputation(mutables)
  12. , DependentNodes(dependentNodes)
  13. {
  14. }
  15. NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
  16. return NUdf::TUnboxedValuePod(ctx.TimeProvider.Now().MicroSeconds());
  17. }
  18. private:
  19. void RegisterDependencies() const final {
  20. std::for_each(DependentNodes.cbegin(), DependentNodes.cend(), std::bind(&TNowWrapper::DependsOn, this, std::placeholders::_1));
  21. }
  22. const TComputationNodePtrVector DependentNodes;
  23. };
  24. }
  25. IComputationNode* WrapNow(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
  26. TComputationNodePtrVector dependentNodes(callable.GetInputsCount());
  27. for (ui32 i = 0; i < callable.GetInputsCount(); ++i) {
  28. dependentNodes[i] = LocateNode(ctx.NodeLocator, callable, i);
  29. }
  30. return new TNowWrapper(ctx.Mutables, std::move(dependentNodes));
  31. }
  32. }
  33. }