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