You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2019/06/02 03:43:50 UTC

[GitHub] [incubator-pinot] xueyumusic commented on a change in pull request #3934: support abs, ceil, exp, floor, ln, log, sqrt math transform function

xueyumusic commented on a change in pull request #3934: support abs,ceil,exp,floor,ln,log,sqrt math transform function
URL: https://github.com/apache/incubator-pinot/pull/3934#discussion_r289625118
 
 

 ##########
 File path: pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/SingleParamMathTransformFunction.java
 ##########
 @@ -0,0 +1,248 @@
+/**
+ * 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.
+ */
+package org.apache.pinot.core.operator.transform.function;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nonnull;
+import org.apache.pinot.core.common.DataSource;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
+import org.apache.pinot.core.util.ArrayCopyUtils;
+
+
+public abstract class SingleParamMathTransformFunction extends BaseTransformFunction {
+  private double _firstLiteral;
+  private TransformFunction _firstTransformFunction;
+  private double[] _result;
+
+  @Override
+  public abstract String getName();
+
+  @Override
+  public void init(@Nonnull List<TransformFunction> arguments, @Nonnull Map<String, DataSource> dataSourceMap) {
+    // Check that there are exactly 1 arguments
+    if (arguments.size() != 1) {
+      throw new IllegalArgumentException("Exactly 1 arguments are required for " + getName() + " transform function");
+    }
+
+    TransformFunction firstArgument = arguments.get(0);
+    if (firstArgument instanceof LiteralTransformFunction) {
+      _firstLiteral = Double.parseDouble(((LiteralTransformFunction) firstArgument).getLiteral());
+    } else {
+      if (!firstArgument.getResultMetadata().isSingleValue()) {
+        throw new IllegalArgumentException("First argument of " + getName() + " transform function must be single-valued");
+      }
+      _firstTransformFunction = firstArgument;
+    }
+  }
+
+  @Override
+  public TransformResultMetadata getResultMetadata() {
+    return DOUBLE_SV_NO_DICTIONARY_METADATA;
+  }
+
+  @SuppressWarnings("Duplicates")
+  @Override
+  public double[] transformToDoubleValuesSV(@Nonnull ProjectionBlock projectionBlock) {
+    if (_result == null) {
+      _result = new double[DocIdSetPlanNode.MAX_DOC_PER_CALL];
+    }
+
+    int length = projectionBlock.getNumDocs();
+
+    if (_firstTransformFunction == null) {
+      Arrays.fill(_result, 0, length, _firstLiteral);
+    } else {
+      switch (_firstTransformFunction.getResultMetadata().getDataType()) {
+        case INT:
+          int[] intValues = _firstTransformFunction.transformToIntValuesSV(projectionBlock);
+          for (int i = 0; i < length; i++) {
+            _result[i] = transformInt(intValues[i]);
 
 Review comment:
   Yes, that makes sense. updated the codes and java doc. Thanks @kishoreg 

----------------------------------------------------------------
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

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org