You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@datasketches.apache.org by "AlexanderSaydakov (via GitHub)" <gi...@apache.org> on 2025/02/25 04:38:22 UTC

[PR] Theta params [datasketches-spark]

AlexanderSaydakov opened a new pull request, #21:
URL: https://github.com/apache/datasketches-spark/pull/21

   (no comment)


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

To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org


Re: [PR] Theta params [datasketches-spark]

Posted by "AlexanderSaydakov (via GitHub)" <gi...@apache.org>.
AlexanderSaydakov commented on code in PR #21:
URL: https://github.com/apache/datasketches-spark/pull/21#discussion_r1972571777


##########
src/main/scala/org/apache/spark/sql/datasketches/theta/aggregate/ThetaSketchAggUnion.scala:
##########
@@ -48,65 +54,81 @@ import org.apache.spark.sql.types.{AbstractDataType, DataType, IntegerType}
 )
 // scalastyle:on line.size.limit
 case class ThetaSketchAggUnion(
-    left: Expression,
-    right: Expression,
+    inputExpr: Expression,
+    lgKExpr: Expression,
+    seedExpr: Expression,
     mutableAggBufferOffset: Int = 0,
     inputAggBufferOffset: Int = 0)
   extends TypedImperativeAggregate[ThetaSketchWrapper]
-    with BinaryLike[Expression]
+    with TernaryLike[Expression]

Review Comment:
   there is a set of overrides for this



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

To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org


Re: [PR] Theta params [datasketches-spark]

Posted by "jmalkin (via GitHub)" <gi...@apache.org>.
jmalkin merged PR #21:
URL: https://github.com/apache/datasketches-spark/pull/21


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

To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org


Re: [PR] Theta params [datasketches-spark]

Posted by "jmalkin (via GitHub)" <gi...@apache.org>.
jmalkin commented on code in PR #21:
URL: https://github.com/apache/datasketches-spark/pull/21#discussion_r1971123772


##########
src/main/scala/org/apache/spark/sql/datasketches/theta/expressions/ThetaExpressions.scala:
##########
@@ -71,3 +73,60 @@ case class ThetaSketchGetEstimate(child: Expression)
     nullSafeCodeGen(ctx, ev, c => s"($c)")
   }
 }
+
+@ExpressionDescription(
+  usage = """
+    _FUNC_(expr) - Returns a summary string that represents the state of the given sketch
+  """,
+  examples = """
+    Example:
+      > SELECT _FUNC_(theta_sketch_agg_build(col)) FROM VALUES (1), (2), (3) tab(col);
+      ### HeapCompactSketch SUMMARY: 
+         Estimate                : 3.0
+         Upper Bound, 95% conf   : 3.0
+         Lower Bound, 95% conf   : 3.0
+         Theta (double)          : 1.0
+         Theta (long)            : 9223372036854775807
+         Theta (long) hex        : 7fffffffffffffff
+         EstMode?                : false
+         Empty?                  : false
+         Ordered?                : true
+         Retained Entries        : 3
+         Seed Hash               : 93cc | 37836
+      ### END SKETCH SUMMARY
+  """
+)
+case class ThetaSketchToString(child: Expression)
+ extends UnaryExpression
+ with ExpectsInputTypes
+ with NullIntolerant {
+
+  override protected def withNewChildInternal(newChild: Expression): ThetaSketchToString = {
+    copy(child = newChild)
+  }
+
+  override def prettyName: String = "theta_sketch_to_string"
+
+  override def inputTypes: Seq[AbstractDataType] = Seq(ThetaSketchType)
+
+  override def dataType: DataType = StringType
+
+  override def nullSafeEval(input: Any): Any = {
+    UTF8String.fromString(Sketch.wrap(Memory.wrap(input.asInstanceOf[Array[Byte]])).toString());
+  }
+
+  override protected def nullSafeCodeGen(ctx: CodegenContext, ev: ExprCode, f: String => String): ExprCode = {
+    val childEval = child.genCode(ctx)
+    val sketch = ctx.freshName("sketch")
+    val code = s"""
+      ${childEval.code}
+      final org.apache.datasketches.theta.Sketch $sketch = org.apache.spark.sql.types.ThetaSketchWrapper.wrapAsReadOnlySketch(${childEval.value});
+      final double ${ev.value} = $sketch.toString());

Review Comment:
   toString() does not return a double



##########
src/main/scala/org/apache/spark/sql/datasketches/theta/aggregate/ThetaSketchAggUnion.scala:
##########
@@ -48,65 +54,81 @@ import org.apache.spark.sql.types.{AbstractDataType, DataType, IntegerType}
 )
 // scalastyle:on line.size.limit
 case class ThetaSketchAggUnion(
-    left: Expression,
-    right: Expression,
+    inputExpr: Expression,
+    lgKExpr: Expression,
+    seedExpr: Expression,
     mutableAggBufferOffset: Int = 0,
     inputAggBufferOffset: Int = 0)
   extends TypedImperativeAggregate[ThetaSketchWrapper]
-    with BinaryLike[Expression]
+    with TernaryLike[Expression]

Review Comment:
   It didn't complain that the children weren't first, second, third?



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

To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org


Re: [PR] Theta params [datasketches-spark]

Posted by "AlexanderSaydakov (via GitHub)" <gi...@apache.org>.
AlexanderSaydakov commented on code in PR #21:
URL: https://github.com/apache/datasketches-spark/pull/21#discussion_r1972572988


##########
src/main/scala/org/apache/spark/sql/datasketches/theta/expressions/ThetaExpressions.scala:
##########
@@ -71,3 +73,60 @@ case class ThetaSketchGetEstimate(child: Expression)
     nullSafeCodeGen(ctx, ev, c => s"($c)")
   }
 }
+
+@ExpressionDescription(
+  usage = """
+    _FUNC_(expr) - Returns a summary string that represents the state of the given sketch
+  """,
+  examples = """
+    Example:
+      > SELECT _FUNC_(theta_sketch_agg_build(col)) FROM VALUES (1), (2), (3) tab(col);
+      ### HeapCompactSketch SUMMARY: 
+         Estimate                : 3.0
+         Upper Bound, 95% conf   : 3.0
+         Lower Bound, 95% conf   : 3.0
+         Theta (double)          : 1.0
+         Theta (long)            : 9223372036854775807
+         Theta (long) hex        : 7fffffffffffffff
+         EstMode?                : false
+         Empty?                  : false
+         Ordered?                : true
+         Retained Entries        : 3
+         Seed Hash               : 93cc | 37836
+      ### END SKETCH SUMMARY
+  """
+)
+case class ThetaSketchToString(child: Expression)
+ extends UnaryExpression
+ with ExpectsInputTypes
+ with NullIntolerant {
+
+  override protected def withNewChildInternal(newChild: Expression): ThetaSketchToString = {
+    copy(child = newChild)
+  }
+
+  override def prettyName: String = "theta_sketch_to_string"
+
+  override def inputTypes: Seq[AbstractDataType] = Seq(ThetaSketchType)
+
+  override def dataType: DataType = StringType
+
+  override def nullSafeEval(input: Any): Any = {
+    UTF8String.fromString(Sketch.wrap(Memory.wrap(input.asInstanceOf[Array[Byte]])).toString());
+  }
+
+  override protected def nullSafeCodeGen(ctx: CodegenContext, ev: ExprCode, f: String => String): ExprCode = {
+    val childEval = child.genCode(ctx)
+    val sketch = ctx.freshName("sketch")
+    val code = s"""
+      ${childEval.code}
+      final org.apache.datasketches.theta.Sketch $sketch = org.apache.spark.sql.types.ThetaSketchWrapper.wrapAsReadOnlySketch(${childEval.value});
+      final double ${ev.value} = $sketch.toString());

Review Comment:
   apparently current tests don't cover this. I am not sure how to test this part



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

To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org


Re: [PR] Theta params [datasketches-spark]

Posted by "jmalkin (via GitHub)" <gi...@apache.org>.
jmalkin commented on code in PR #21:
URL: https://github.com/apache/datasketches-spark/pull/21#discussion_r1972576833


##########
src/main/scala/org/apache/spark/sql/datasketches/theta/expressions/ThetaExpressions.scala:
##########
@@ -71,3 +73,60 @@ case class ThetaSketchGetEstimate(child: Expression)
     nullSafeCodeGen(ctx, ev, c => s"($c)")
   }
 }
+
+@ExpressionDescription(
+  usage = """
+    _FUNC_(expr) - Returns a summary string that represents the state of the given sketch
+  """,
+  examples = """
+    Example:
+      > SELECT _FUNC_(theta_sketch_agg_build(col)) FROM VALUES (1), (2), (3) tab(col);
+      ### HeapCompactSketch SUMMARY: 
+         Estimate                : 3.0
+         Upper Bound, 95% conf   : 3.0
+         Lower Bound, 95% conf   : 3.0
+         Theta (double)          : 1.0
+         Theta (long)            : 9223372036854775807
+         Theta (long) hex        : 7fffffffffffffff
+         EstMode?                : false
+         Empty?                  : false
+         Ordered?                : true
+         Retained Entries        : 3
+         Seed Hash               : 93cc | 37836
+      ### END SKETCH SUMMARY
+  """
+)
+case class ThetaSketchToString(child: Expression)
+ extends UnaryExpression
+ with ExpectsInputTypes
+ with NullIntolerant {
+
+  override protected def withNewChildInternal(newChild: Expression): ThetaSketchToString = {
+    copy(child = newChild)
+  }
+
+  override def prettyName: String = "theta_sketch_to_string"
+
+  override def inputTypes: Seq[AbstractDataType] = Seq(ThetaSketchType)
+
+  override def dataType: DataType = StringType
+
+  override def nullSafeEval(input: Any): Any = {
+    UTF8String.fromString(Sketch.wrap(Memory.wrap(input.asInstanceOf[Array[Byte]])).toString());
+  }
+
+  override protected def nullSafeCodeGen(ctx: CodegenContext, ev: ExprCode, f: String => String): ExprCode = {
+    val childEval = child.genCode(ctx)
+    val sketch = ctx.freshName("sketch")
+    val code = s"""
+      ${childEval.code}
+      final org.apache.datasketches.theta.Sketch $sketch = org.apache.spark.sql.types.ThetaSketchWrapper.wrapAsReadOnlySketch(${childEval.value});
+      final double ${ev.value} = $sketch.toString());

Review Comment:
   I'll see if I can create codegen and non-codegen routes for testing ... maybe this weekend.  but i worry it'll still fall back silently, and i'm not sure what we can do about that



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

To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org


Re: [PR] Theta params [datasketches-spark]

Posted by "AlexanderSaydakov (via GitHub)" <gi...@apache.org>.
AlexanderSaydakov commented on code in PR #21:
URL: https://github.com/apache/datasketches-spark/pull/21#discussion_r1972572028


##########
src/main/scala/org/apache/spark/sql/datasketches/theta/expressions/ThetaExpressions.scala:
##########
@@ -71,3 +73,60 @@ case class ThetaSketchGetEstimate(child: Expression)
     nullSafeCodeGen(ctx, ev, c => s"($c)")
   }
 }
+
+@ExpressionDescription(
+  usage = """
+    _FUNC_(expr) - Returns a summary string that represents the state of the given sketch
+  """,
+  examples = """
+    Example:
+      > SELECT _FUNC_(theta_sketch_agg_build(col)) FROM VALUES (1), (2), (3) tab(col);
+      ### HeapCompactSketch SUMMARY: 
+         Estimate                : 3.0
+         Upper Bound, 95% conf   : 3.0
+         Lower Bound, 95% conf   : 3.0
+         Theta (double)          : 1.0
+         Theta (long)            : 9223372036854775807
+         Theta (long) hex        : 7fffffffffffffff
+         EstMode?                : false
+         Empty?                  : false
+         Ordered?                : true
+         Retained Entries        : 3
+         Seed Hash               : 93cc | 37836
+      ### END SKETCH SUMMARY
+  """
+)
+case class ThetaSketchToString(child: Expression)
+ extends UnaryExpression
+ with ExpectsInputTypes
+ with NullIntolerant {
+
+  override protected def withNewChildInternal(newChild: Expression): ThetaSketchToString = {
+    copy(child = newChild)
+  }
+
+  override def prettyName: String = "theta_sketch_to_string"
+
+  override def inputTypes: Seq[AbstractDataType] = Seq(ThetaSketchType)
+
+  override def dataType: DataType = StringType
+
+  override def nullSafeEval(input: Any): Any = {
+    UTF8String.fromString(Sketch.wrap(Memory.wrap(input.asInstanceOf[Array[Byte]])).toString());
+  }
+
+  override protected def nullSafeCodeGen(ctx: CodegenContext, ev: ExprCode, f: String => String): ExprCode = {
+    val childEval = child.genCode(ctx)
+    val sketch = ctx.freshName("sketch")
+    val code = s"""
+      ${childEval.code}
+      final org.apache.datasketches.theta.Sketch $sketch = org.apache.spark.sql.types.ThetaSketchWrapper.wrapAsReadOnlySketch(${childEval.value});
+      final double ${ev.value} = $sketch.toString());

Review Comment:
   oh, will fix



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

To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org


Re: [PR] Theta params [datasketches-spark]

Posted by "jmalkin (via GitHub)" <gi...@apache.org>.
jmalkin commented on code in PR #21:
URL: https://github.com/apache/datasketches-spark/pull/21#discussion_r1972576235


##########
src/main/scala/org/apache/spark/sql/datasketches/theta/expressions/ThetaExpressions.scala:
##########
@@ -71,3 +73,60 @@ case class ThetaSketchGetEstimate(child: Expression)
     nullSafeCodeGen(ctx, ev, c => s"($c)")
   }
 }
+
+@ExpressionDescription(
+  usage = """
+    _FUNC_(expr) - Returns a summary string that represents the state of the given sketch
+  """,
+  examples = """
+    Example:
+      > SELECT _FUNC_(theta_sketch_agg_build(col)) FROM VALUES (1), (2), (3) tab(col);
+      ### HeapCompactSketch SUMMARY: 
+         Estimate                : 3.0
+         Upper Bound, 95% conf   : 3.0
+         Lower Bound, 95% conf   : 3.0
+         Theta (double)          : 1.0
+         Theta (long)            : 9223372036854775807
+         Theta (long) hex        : 7fffffffffffffff
+         EstMode?                : false
+         Empty?                  : false
+         Ordered?                : true
+         Retained Entries        : 3
+         Seed Hash               : 93cc | 37836
+      ### END SKETCH SUMMARY
+  """
+)
+case class ThetaSketchToString(child: Expression)
+ extends UnaryExpression
+ with ExpectsInputTypes
+ with NullIntolerant {
+
+  override protected def withNewChildInternal(newChild: Expression): ThetaSketchToString = {
+    copy(child = newChild)
+  }
+
+  override def prettyName: String = "theta_sketch_to_string"
+
+  override def inputTypes: Seq[AbstractDataType] = Seq(ThetaSketchType)
+
+  override def dataType: DataType = StringType
+
+  override def nullSafeEval(input: Any): Any = {
+    UTF8String.fromString(Sketch.wrap(Memory.wrap(input.asInstanceOf[Array[Byte]])).toString());
+  }
+
+  override protected def nullSafeCodeGen(ctx: CodegenContext, ev: ExprCode, f: String => String): ExprCode = {
+    val childEval = child.genCode(ctx)
+    val sketch = ctx.freshName("sketch")
+    val code = s"""
+      ${childEval.code}
+      final org.apache.datasketches.theta.Sketch $sketch = org.apache.spark.sql.types.ThetaSketchWrapper.wrapAsReadOnlySketch(${childEval.value});
+      final double ${ev.value} = $sketch.toString());

Review Comment:
   I'll see if I can test later, but i _think_ what likely happens is that it tries codegen, gets an exception since String can't be assinged to double, and then falls back to non-codegen.



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

To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org


Re: [PR] Theta params [datasketches-spark]

Posted by "jmalkin (via GitHub)" <gi...@apache.org>.
jmalkin commented on code in PR #21:
URL: https://github.com/apache/datasketches-spark/pull/21#discussion_r1972576833


##########
src/main/scala/org/apache/spark/sql/datasketches/theta/expressions/ThetaExpressions.scala:
##########
@@ -71,3 +73,60 @@ case class ThetaSketchGetEstimate(child: Expression)
     nullSafeCodeGen(ctx, ev, c => s"($c)")
   }
 }
+
+@ExpressionDescription(
+  usage = """
+    _FUNC_(expr) - Returns a summary string that represents the state of the given sketch
+  """,
+  examples = """
+    Example:
+      > SELECT _FUNC_(theta_sketch_agg_build(col)) FROM VALUES (1), (2), (3) tab(col);
+      ### HeapCompactSketch SUMMARY: 
+         Estimate                : 3.0
+         Upper Bound, 95% conf   : 3.0
+         Lower Bound, 95% conf   : 3.0
+         Theta (double)          : 1.0
+         Theta (long)            : 9223372036854775807
+         Theta (long) hex        : 7fffffffffffffff
+         EstMode?                : false
+         Empty?                  : false
+         Ordered?                : true
+         Retained Entries        : 3
+         Seed Hash               : 93cc | 37836
+      ### END SKETCH SUMMARY
+  """
+)
+case class ThetaSketchToString(child: Expression)
+ extends UnaryExpression
+ with ExpectsInputTypes
+ with NullIntolerant {
+
+  override protected def withNewChildInternal(newChild: Expression): ThetaSketchToString = {
+    copy(child = newChild)
+  }
+
+  override def prettyName: String = "theta_sketch_to_string"
+
+  override def inputTypes: Seq[AbstractDataType] = Seq(ThetaSketchType)
+
+  override def dataType: DataType = StringType
+
+  override def nullSafeEval(input: Any): Any = {
+    UTF8String.fromString(Sketch.wrap(Memory.wrap(input.asInstanceOf[Array[Byte]])).toString());
+  }
+
+  override protected def nullSafeCodeGen(ctx: CodegenContext, ev: ExprCode, f: String => String): ExprCode = {
+    val childEval = child.genCode(ctx)
+    val sketch = ctx.freshName("sketch")
+    val code = s"""
+      ${childEval.code}
+      final org.apache.datasketches.theta.Sketch $sketch = org.apache.spark.sql.types.ThetaSketchWrapper.wrapAsReadOnlySketch(${childEval.value});
+      final double ${ev.value} = $sketch.toString());

Review Comment:
   I'll see if I can create codegen and non-codegen routes for testing ... maybe this weekend



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

To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org