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-unsubscr...@datasketches.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@datasketches.apache.org For additional commands, e-mail: dev-h...@datasketches.apache.org