GitHub user dadepo closed a discussion: How to solve "Error: This feature is 
not implemented: Can't create a scalar from array of type "Map"

How can I fix an error of this kind

```
Error: This feature is not implemented: Can't create a scalar from array of 
type "Map(...
```

Background, I have a UDF that mimics json_build_object from postgres. With a 
table like

```
let df = ctx.sql(r#"
select * from test"#).await?;
df.show().await?;

+-----------+-----------+-----------+
| clientid  | name      | parentid  |
+-----------+-----------+-----------+
| c-string1 | n-string1 | p-string1 |
| c-string2 | n-string2 | p-string2 |
+-----------+-----------+-----------+
```

I can build a json like this fine

```
        let df = ctx.sql(r#"
        select json_build_object('name', name, 'type', 'test')
        from test"#).await?;
        df.show().await?;

+---------------------------------------------------------------------+
| json_build_object(Utf8("name"),test.name,Utf8("type"),Utf8("test")) |
+---------------------------------------------------------------------+
| {name: n-string1, type: test}                                       |
| {name: n-string2, type: test}                                       |
+---------------------------------------------------------------------+
```

But if I remove name or any other column that exist in the table, I get the 
error

```
        let df = ctx.sql(r#"
        select json_build_object('type', 'test')
        from test"#).await?;
        df.show().await?;

Error: This feature is not implemented: Can't create a scalar from array of 
type "Map(Field { name: "entries", data_type: Struct([Field { name: "keys", 
data_type: Utf8, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: 
{} }, Field { name: "values", data_type: Utf8, nullable: true, dict_id: 0, 
dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, 
dict_is_ordered: false, metadata: {} }, false)"
```

A simple work around will be to always include a column from the table in the 
query, but unfortunately i cannot guarantee this. Especially when I have use 
case where json_build_object works on computed values or values created via 
other udfs.

How can I make my UDF not dependent on the present of a column? For example I 
can use the make_array function in this way. That is, I can use it without 
including a column from the table

```
        let df = ctx.sql(r#"
        select make_array('type', 'test')
        from test"#).await?;
        df.show().await?;

+--------------------------------------+
| makearray(Utf8("type"),Utf8("test")) |
+--------------------------------------+
| [type, test]                         |
| [type, test]                         |
+--------------------------------------+
```

GitHub link: https://github.com/apache/datafusion/discussions/6474

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to