Ted-Jiang opened a new issue, #2330:
URL: https://github.com/apache/arrow-datafusion/issues/2330

   **Is your feature request related to a problem or challenge? Please describe 
what you are trying to do.**
   Hi,  I have met some problems.  I want to implement an expr `inline` which 
   
   inline(expr) - Explodes an array of structs into a table.:
   ```
   > SELECT inline(array(struct(1, 'a'), struct(2, 'b')));
    1  a
    2  b
   ```
   
    i have two solutions:
   1. add inline in ScalarFunction , But  i found 
   ```
   pub type ScalarFunctionImplementation =
       Arc<dyn Fn(&[ColumnarValue]) -> Result<ColumnarValue> + Send + Sync>;
   ```
   
   In this case, I can not produce more than two columns by using  
ScalarFunction, am i right ?
   
   2. implement a Expr like `Wildcard`
   I think this is not a good way 😂
   
   Could anyone give me some advice ?
   
   in spark i found, is there something similar?
   ```
   /**
    * Explodes an array of structs into a table.
    */
   // scalastyle:off line.size.limit line.contains.tab
   @ExpressionDescription(
     usage = "_FUNC_(expr) - Explodes an array of structs into a table. Uses 
column names col1, col2, etc. by default unless specified otherwise.",
     examples = """
       Examples:
         > SELECT _FUNC_(array(struct(1, 'a'), struct(2, 'b')));
          1     a
          2     b
     """,
     since = "2.0.0",
     group = "generator_funcs")
   // scalastyle:on line.size.limit line.contains.tab
   case class Inline(child: Expression) extends UnaryExpression with 
CollectionGenerator {
     override val inline: Boolean = true
     override val position: Boolean = false
   
     override def checkInputDataTypes(): TypeCheckResult = child.dataType match 
{
       case ArrayType(st: StructType, _) =>
         TypeCheckResult.TypeCheckSuccess
       case _ =>
         TypeCheckResult.TypeCheckFailure(
           s"input to function $prettyName should be array of struct type, " +
             s"not ${child.dataType.catalogString}")
     }
   
     override def elementSchema: StructType = child.dataType match {
       case ArrayType(st: StructType, _) => st
     }
   
     override def collectionType: DataType = child.dataType
   
     private lazy val numFields = elementSchema.fields.length
   
     override def eval(input: InternalRow): TraversableOnce[InternalRow] = {
       val inputArray = child.eval(input).asInstanceOf[ArrayData]
       if (inputArray == null) {
         Nil
       } else {
         for (i <- 0 until inputArray.numElements())
           yield inputArray.getStruct(i, numFields)
       }
     }
   
     override protected def doGenCode(ctx: CodegenContext, ev: ExprCode): 
ExprCode = {
       child.genCode(ctx)
     }
   
     override protected def withNewChildInternal(newChild: Expression): Inline 
= copy(child = newChild)
   }
   ```
   
   **Describe the solution you'd like**
   A clear and concise description of what you want to happen.
   
   **Describe alternatives you've considered**
   A clear and concise description of any alternative solutions or features 
you've considered.
   
   **Additional context**
   Add any other context or screenshots about the feature request here.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to