Skip to content

Conversation

@zhichao-li
Copy link
Contributor

https://issues.apache.org/jira/browse/SPARK-8221

One concern is the result would be negative if the divisor is not positive( i.e pmod(7, -3) ), but the behavior is the same as hive.

@SparkQA
Copy link

SparkQA commented Jun 12, 2015

Test build #34760 has finished for PR 6783 at commit b18a861.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to support Decimal type as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Byte, Long etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I've just checked the Hive doc, seems only Int and Double types are accepted, let's do the same thing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's important that we should not generate a result different from hive, but I think we are free to extend when hive would throw an exception, only if we consider it a reasonable change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

however I think it is ok to leave Decimal unsupported here.:P

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to hive, I think we need to support Decimal...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it's not the same as the doc described, https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF
The reason for this is conform to the BinaryMathExpression, which supposed to be DoubleType, just the like pow etc.

@SparkQA
Copy link

SparkQA commented Jun 15, 2015

Test build #34900 has finished for PR 6783 at commit 01a0f3b.

  • This patch fails Scala style tests.
  • This patch does not merge cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@SparkQA
Copy link

SparkQA commented Jun 15, 2015

Test build #34903 has finished for PR 6783 at commit ca9cc53.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 15, 2015

Test build #34912 has finished for PR 6783 at commit 90e588c.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@SparkQA
Copy link

SparkQA commented Jun 16, 2015

Test build #34963 has finished for PR 6783 at commit 88c63ab.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@adrian-wang
Copy link
Contributor

LGTM except the full type APIs

@zhichao-li
Copy link
Contributor Author

@adrian-wang @chenghao-intel , wondering what type of api we should reserve regarding to this kind of api def pmod(leftName: String, r: Integer): Column ? I guess it would be a good thing that enable such input: select pmod(columName, 10) .. from ...

@adrian-wang
Copy link
Contributor

@zhichao-li if you are using sql(), even without those APIs, the query will still work. It is just for dataframe api

@zhichao-li
Copy link
Contributor Author

hum... right . It just give us a convenient way to enabledf.select(pmod($"a", 10)) without using verbose literal wrapper. I'll remove it if not too much benefit we can gain from those.

@chenghao-intel
Copy link
Contributor

Adding API is easier, but remove the published API is difficult, let's keep the DF API simple as much as possible.

@SparkQA
Copy link

SparkQA commented Jun 16, 2015

Test build #34975 has finished for PR 6783 at commit b5233a2.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about follow Remainder to use Integral.rem to do the computation? That will save a lot of code here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea , but seems like the clac result would be a little bit different with the expected result. pmod(7.2, 4.1), actual: 3.099999999999999, expected: 3.1000000000000005 . I'm keen on keeping it this way if not obvious downside.

  private lazy val integral = dataType match {
    case i: IntegralType => i.integral.asInstanceOf[Integral[Any]]
    case i: FractionalType => i.asIntegral.asInstanceOf[Integral[Any]]
    case i: DecimalType => i.asIntegral.asInstanceOf[Integral[Any]]
  }
  protected override def evalInternal(a: Any, n: Any) = 
    integral.rem(integral.plus(integral.rem(a, n), n), n)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok maybe you can send another PR to fix Divide in this way too, as it's result is different from hive's.

@SparkQA
Copy link

SparkQA commented Jun 18, 2015

Test build #35116 has finished for PR 6783 at commit 372b66c.

  • This patch fails Spark unit tests.
  • This patch does not merge cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@SparkQA
Copy link

SparkQA commented Jun 19, 2015

Test build #35203 has finished for PR 6783 at commit 9be7e4c.

  • This patch fails MiMa tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@chenghao-intel
Copy link
Contributor

retest this please.

1 similar comment
@zhichao-li
Copy link
Contributor Author

retest this please.

@SparkQA
Copy link

SparkQA commented Jun 19, 2015

Test build #35209 has finished for PR 6783 at commit 9be7e4c.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think you need to override this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it's a must since symbol is abstract in BinaryOperator

@zhichao-li
Copy link
Contributor Author

retest this please. Fail by timeout after 1 minute

@SparkQA
Copy link

SparkQA commented Jul 14, 2015

Test build #9 has finished for PR 6783 at commit 0493dc4.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@SparkQA
Copy link

SparkQA commented Jul 14, 2015

Test build #11 has finished for PR 6783 at commit 0493dc4.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@zhichao-li
Copy link
Contributor Author

retest this please.

@SparkQA
Copy link

SparkQA commented Jul 14, 2015

Test build #37208 has finished for PR 6783 at commit 0493dc4.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@SparkQA
Copy link

SparkQA commented Jul 14, 2015

Test build #37219 has finished for PR 6783 at commit 0493dc4.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@SparkQA
Copy link

SparkQA commented Jul 14, 2015

Test build #13 has finished for PR 6783 at commit 0493dc4.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@zhichao-li
Copy link
Contributor Author

retest this please.

@SparkQA
Copy link

SparkQA commented Jul 15, 2015

Test build #18 has finished for PR 6783 at commit 0493dc4.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@SparkQA
Copy link

SparkQA commented Jul 15, 2015

Test build #37291 has finished for PR 6783 at commit 0493dc4.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@zhichao-li
Copy link
Contributor Author

retest this please.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this -- and after #7348 is merged, you'd need to define inputType to be NumericType

@rxin
Copy link
Contributor

rxin commented Jul 15, 2015

@zhichao-li this looks pretty good now. Just need to update it to work with the latest type checking framework.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should override toString to be s"pmod($left, $right)"

@SparkQA
Copy link

SparkQA commented Jul 15, 2015

Test build #37332 has finished for PR 6783 at commit 0493dc4.

  • This patch fails to build.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@rxin
Copy link
Contributor

rxin commented Jul 15, 2015

Jenkins, retest this please.

@SparkQA
Copy link

SparkQA commented Jul 15, 2015

Test build #20 has finished for PR 6783 at commit 0493dc4.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@SparkQA
Copy link

SparkQA commented Jul 15, 2015

Test build #37321 has finished for PR 6783 at commit 0493dc4.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

@SparkQA
Copy link

SparkQA commented Jul 15, 2015

Test build #37334 has finished for PR 6783 at commit 7083eb9.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • class LDAModel(JavaModelWrapper):
    • class LDA(object):
    • trait ImplicitCastInputTypes extends ExpectsInputTypes
    • abstract class BinaryOperator extends BinaryExpression with ExpectsInputTypes
    • case class UnaryMinus(child: Expression) extends UnaryExpression with ExpectsInputTypes
    • case class UnaryPositive(child: Expression) extends UnaryExpression with ExpectsInputTypes
    • case class Abs(child: Expression) extends UnaryExpression with ExpectsInputTypes
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic
    • case class BitwiseNot(child: Expression) extends UnaryExpression with ExpectsInputTypes
    • case class Factorial(child: Expression) extends UnaryExpression with ImplicitCastInputTypes
    • case class Hex(child: Expression) extends UnaryExpression with ImplicitCastInputTypes
    • case class Unhex(child: Expression) extends UnaryExpression with ImplicitCastInputTypes
    • case class Round(child: Expression, scale: Expression)
    • case class Md5(child: Expression) extends UnaryExpression with ImplicitCastInputTypes
    • case class Sha1(child: Expression) extends UnaryExpression with ImplicitCastInputTypes
    • case class Crc32(child: Expression) extends UnaryExpression with ImplicitCastInputTypes
    • case class Not(child: Expression)
    • case class And(left: Expression, right: Expression) extends BinaryOperator with Predicate
    • case class Or(left: Expression, right: Expression) extends BinaryOperator with Predicate
    • trait StringRegexExpression extends ImplicitCastInputTypes
    • trait String2StringExpression extends ImplicitCastInputTypes
    • trait StringComparison extends ImplicitCastInputTypes
    • case class StringSpace(child: Expression) extends UnaryExpression with ImplicitCastInputTypes
    • case class StringLength(child: Expression) extends UnaryExpression with ImplicitCastInputTypes
    • case class Ascii(child: Expression) extends UnaryExpression with ImplicitCastInputTypes
    • case class Base64(child: Expression) extends UnaryExpression with ImplicitCastInputTypes
    • case class UnBase64(child: Expression) extends UnaryExpression with ImplicitCastInputTypes

@SparkQA
Copy link

SparkQA commented Jul 15, 2015

Test build #37335 has finished for PR 6783 at commit 7083eb9.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • case class Pmod(left: Expression, right: Expression) extends BinaryArithmetic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this symbol is not needed as you have override toString, however we have to implement it here as it's defined abstract in BinaryOperator. We may need to fix it in the future.

@cloud-fan
Copy link
Contributor

lgtm

@rxin
Copy link
Contributor

rxin commented Jul 15, 2015

Alright I'm merging this. Thanks a lot for working on it.

@asfgit asfgit closed this in a938527 Jul 15, 2015
@zhichao-li zhichao-li deleted the pmod2 branch September 9, 2015 06:06
case dt: DecimalType =>
val decimalAdd = "$plus"
s"""
${ctx.javaType(dataType)} r = $eval1.remainder($eval2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi there is a bug here -- if we use pmod twice, this will fail codegen because r is not unique.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants