You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by viirya <gi...@git.apache.org> on 2017/03/22 07:03:49 UTC

[GitHub] spark pull request #17359: [SPARK-20028][SQL] Add aggreagate expression nGra...

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

    https://github.com/apache/spark/pull/17359#discussion_r107343519
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/NGrams.scala ---
    @@ -0,0 +1,258 @@
    +/*
    + * 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.sql.catalyst.expressions.aggregate
    +
    +import java.nio.ByteBuffer
    +import java.util.HashMap
    +
    +import org.apache.spark.serializer.KryoSerializer
    +import org.apache.spark.SparkConf
    +import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
    +import org.apache.spark.sql.catalyst.analysis.TypeCheckResult._
    +import org.apache.spark.sql.catalyst.expressions.{Expression, ExpressionDescription, ImplicitCastInputTypes, Literal}
    +import org.apache.spark.sql.catalyst.expressions.aggregate.NGrams.NGramBuffer
    +import org.apache.spark.sql.catalyst.InternalRow
    +import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, GenericArrayData}
    +import org.apache.spark.sql.types._
    +import org.apache.spark.unsafe.types.UTF8String
    +
    +/**
    + * Return the top-k n-grams in rows that consist of sequences of strings.
    + */
    +@ExpressionDescription(
    +  usage = """
    +    _FUNC_(expr, n, k, accuracy) - Estimates the top-k n-grams in rows that consist of sequences
    +      of strings, represented as arrays of strings, or arrays of arrays of strings. 'accuracy' is an
    +      optional precision factor that controls memory usage.
    +      The parameter 'n' specifies what type of n-grams are being estimated. Unigrams are n = 1, and
    +      bigrams are n = 2. Generally, n will not be greater than about 5. The 'k' parameter specifies
    +      how many of the highest-frequency n-grams will be returned by the UDAF. The optional precision
    +      factor 'accuracy' specifies how much memory to use for estimation; more memory will give
    +      more accurate frequency counts, but could crash the JVM. The value will be the max between
    +      'accuracy'(0 if it's not specified) and 1000/k, which indicates the max number of n-grams
    +      which are kept in the internal HashMap.
    +      The output is an array of maps with the top-k n-grams and corresponding frequency.
    +  """,
    +  extended = """
    +    Examples:
    +      > SELECT ngrams(array('abc', 'abc', 'bcd', 'abc', 'bcd'), 2, 4);
    +       [["abc","bcd"]:2.0},
    --- End diff --
    
    hmm, doesn't "abc" show 3 times?


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