beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [beam] TheNeuralBit commented on a change in pull request #10757: Starting implementation of dataframes for Beam
Date Fri, 06 Mar 2020 20:43:43 GMT
TheNeuralBit commented on a change in pull request #10757: Starting implementation of dataframes
for Beam
URL: https://github.com/apache/beam/pull/10757#discussion_r379665834
 
 

 ##########
 File path: sdks/python/apache_beam/dataframe/expressions.py
 ##########
 @@ -0,0 +1,155 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+class Session(object):
+  """A session represents a mapping of expressions to concrete values.
+
+  The bindings typically include required placeholders, but may be any
+  intermediate expression as well.
+  """
+  def __init__(self, bindings={}):
+    self._bindings = dict(bindings)
+
+  def evaluate(self, expr):
+    if expr not in self._bindings:
+      self._bindings[expr] = expr.evaluate_at(self)
+    return self._bindings[expr]
+
+  def lookup(self, expr):
+    return self._bindings[expr]
+
+
+class Expression(object):
+  """An expression is an operation bound to a set of arguments.
+
+  An expression represents a deferred tree of operations, which can be
+  evaluated at a specific bindings of root expressions to values.
+  """
+  def __init__(self, name, proxy=None, _id=None):
+    self._name = name
+    self._proxy = proxy
+    # Store for preservation through pickling.
+    self._id = _id or '%s_%s' % (name, id(self))
+
+  def proxy(self):
+    return self._proxy
+
+  def __hash__(self):
+    return hash(self._id)
+
+  def __eq__(self):
+    return self._id == other._id
+
+  def __ne__(self, other):
+    return not self == other
+
+  def evaluate_at(self, session):
+    """Returns the result of self with the bindings given in session."""
+    raise NotImplementedError(type(self))
+
+  def requires_partition_by_index(self):
+    """Whether this expression requires its argument(s) to be partitioned
+    by index."""
+    # TODO: It might be necessary to support partitioning by part of the index,
+    # for some args, which would require returning more than a boolean here.
+    raise NotImplementedError(type(self))
+
+  def preserves_partition_by_index(self):
+    """Whether the result of this expression will be partitioned by index
+    whenever all of its inputs are partitioned by index."""
+    raise NotImplementedError(type(self))
+
+
+class PlaceholderExpression(Expression):
+  """An expression whose value must be explicitly bound in the session."""
+  def __init__(self, proxy):
+    super(PlaceholderExpression, self).__init__('placeholder', proxy)
+
+  def args(self):
+    return ()
+
+  def evaluate_at(self, session):
+    return session.lookup(self)
+
+  def requires_partition_by_index(self):
+    return False
+
+  def preserves_partition_by_index(self):
+    return False
+
+
+class ConstantExpression(Expression):
+  """An expression whose value is known at compile time."""
 
 Review comment:
   Would "pipeline construction time" be more accurate here?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message