You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by srowen <gi...@git.apache.org> on 2017/01/24 15:59:42 UTC

[GitHub] spark pull request #16329: [SPARK-16046][DOCS] Aggregations in the Spark SQL...

Github user srowen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16329#discussion_r97580048
  
    --- Diff: examples/src/main/java/org/apache/spark/examples/sql/JavaUserDefinedTypedAggregation.java ---
    @@ -0,0 +1,160 @@
    +/*
    + * 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.spark.examples.sql;
    +
    +// $example on:typed_custom_aggregation$
    +import java.io.Serializable;
    +
    +import org.apache.spark.sql.Dataset;
    +import org.apache.spark.sql.Encoder;
    +import org.apache.spark.sql.Encoders;
    +import org.apache.spark.sql.SparkSession;
    +import org.apache.spark.sql.TypedColumn;
    +import org.apache.spark.sql.expressions.Aggregator;
    +// $example off:typed_custom_aggregation$
    +
    +public class JavaUserDefinedTypedAggregation {
    +
    +  // $example on:typed_custom_aggregation$
    +  public static class Employee implements Serializable {
    +    private String name;
    +    private long salary;
    +
    +    // Constructors, getters, setters...
    +    // $example off:typed_custom_aggregation$
    +    public String getName() {
    +      return name;
    +    }
    +
    +    public void setName(String name) {
    +      this.name = name;
    +    }
    +
    +    public long getSalary() {
    +      return salary;
    +    }
    +
    +    public void setSalary(long salary) {
    +      this.salary = salary;
    +    }
    +    // $example on:typed_custom_aggregation$
    +  }
    +
    +  public static class Average implements Serializable  {
    +    private long sum;
    +    private long count;
    +
    +    // Constructors, getters, setters...
    +    // $example off:typed_custom_aggregation$
    +    public Average() {
    +    }
    +
    +    public Average(long sum, long count) {
    +      this.sum = sum;
    +      this.count = count;
    +    }
    +
    +    public long getSum() {
    +      return sum;
    +    }
    +
    +    public void setSum(long sum) {
    +      this.sum = sum;
    +    }
    +
    +    public long getCount() {
    +      return count;
    +    }
    +
    +    public void setCount(long count) {
    +      this.count = count;
    +    }
    +    // $example on:typed_custom_aggregation$
    +  }
    +
    +  public static class MyAverage extends Aggregator<Employee, Average, Double> {
    +    // A zero value for this aggregation. Should satisfy the property that any b + zero = b
    +    public Average zero() {
    --- End diff --
    
    Is this meant to be `MyAverage`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org