4

I'm trying to create a glue table with a column that maps to an array of struct with a defined schema. Using the aws_glue_alpha experimental construct, definition of an array of struct is possible only via this code syntax

glue.Schema.array(
    input_string='struct',
    is_primitive=False,
)

I want to do something like

glue.Schema.array(
  glue.Schema.struct(
       columns=[...]
)    
)

How can I achieve this?

How can you explain these examples work that do exactly what I want?

2 Answers 2

1

Currently, I don't think you can nest glue.Schema.struct() inside glue.Schema.array() directly in aws_glue_alpha . Instead, define struct schema separately, then use it in the array.

struct_schema = glue.Schema.struct([
    glue.Column(name="field1", type=glue.Schema.string),
    glue.Column(name="field2", type=glue.Schema.int),
])

array_of_struct = glue.Schema.array(struct_schema)

I believe this works with aws-glue-alpha CDK.

Sign up to request clarification or add additional context in comments.

1 Comment

What is the difference between this and directly nesting? It's the same imo. Anyway I tried it, and I still get TypeError: Schema.array() takes 1 positional argument but 2 were given
1

By inspecting the source code of the npm package, I understood what exactly is that inputString parameter. Essentially, every schema method returns a Type instance which has two properties: inputString & isPrimitive. What I tried (and worked out) is storing a struct definition in a separate variable and pass it to the array method like

glue.Schema.array(input_string=my_struct.input_string, is_primitive=my_struct.is_primitive

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.