chamikaramj commented on code in PR #30808: URL: https://github.com/apache/beam/pull/30808#discussion_r1546621758
########## sdks/java/managed/src/main/java/org/apache/beam/sdk/managed/Managed.java: ########## @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.managed; + +import com.google.auto.value.AutoValue; +import java.util.Map; +import javax.annotation.Nullable; +import org.apache.beam.sdk.schemas.transforms.SchemaTransform; +import org.apache.beam.sdk.values.PCollectionRowTuple; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; + +public class Managed { + public static final String READ = "READ"; + public static final String WRITE = "WRITE"; + + public enum IO { + ICEBERG + } + + public static Read read() { + return new AutoValue_Managed_Read.Builder().build(); + } + + @AutoValue + public abstract static class Read extends SchemaTransform { + private final Map<IO, String> identifiers = + ImmutableMap.of(IO.ICEBERG, "beam:schematransform:org.apache.beam:iceberg_read:v1"); + + abstract IO getSource(); + + abstract @Nullable String getConfig(); + + abstract @Nullable String getConfigUrl(); + + abstract Builder toBuilder(); + + @AutoValue.Builder + abstract static class Builder { + abstract Builder setSource(IO source); + + abstract Builder setConfig(String config); + + abstract Builder setConfigUrl(String configUrl); + + abstract Read build(); + } + + public Read from(IO source) { + return toBuilder().setSource(source).build(); + } + + public Read withConfigUrl(String configUrl) { + return toBuilder().setConfigUrl(configUrl).build(); + } + + public Read withConfig(String config) { + return toBuilder().setConfigUrl(config).build(); + } + + public Read withConfig(Map<String, Object> config) { + return toBuilder().setConfigUrl(mapToYamlString(config)).build(); + } + + @Override + public PCollectionRowTuple expand(PCollectionRowTuple input) { + String underlyingTransformIdentifier = identifiers.get(getSource()); + + ManagedSchemaTransformProvider.ManagedConfig managedConfig = + ManagedSchemaTransformProvider.ManagedConfig.builder() + .setIdentifier(underlyingTransformIdentifier) + .setType(READ) + .setConfig(getConfig()) + .setConfigUrl(getConfigUrl()) + .build(); + + SchemaTransform underlyingTransform = ManagedSchemaTransformProvider.of().from(managedConfig); + + return input.apply(underlyingTransform); + } + } + + public static Write write() { + return new AutoValue_Managed_Write.Builder().build(); + } + + @AutoValue + public abstract static class Write extends SchemaTransform { Review Comment: Ditto (similar changes as `Read`). ########## sdks/java/managed/src/main/java/org/apache/beam/sdk/managed/Managed.java: ########## @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.managed; + +import com.google.auto.value.AutoValue; +import java.util.Map; +import javax.annotation.Nullable; +import org.apache.beam.sdk.schemas.transforms.SchemaTransform; +import org.apache.beam.sdk.values.PCollectionRowTuple; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; + +public class Managed { + public static final String READ = "READ"; + public static final String WRITE = "WRITE"; + + public enum IO { + ICEBERG + } + + public static Read read() { + return new AutoValue_Managed_Read.Builder().build(); + } + + @AutoValue + public abstract static class Read extends SchemaTransform { + private final Map<IO, String> identifiers = + ImmutableMap.of(IO.ICEBERG, "beam:schematransform:org.apache.beam:iceberg_read:v1"); + + abstract IO getSource(); Review Comment: Is this needed ? Probably we should not introduce a "new" concept `IO` to the API. ########## sdks/java/managed/src/main/java/org/apache/beam/sdk/managed/Managed.java: ########## @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.managed; + +import com.google.auto.value.AutoValue; +import java.util.Map; +import javax.annotation.Nullable; +import org.apache.beam.sdk.schemas.transforms.SchemaTransform; +import org.apache.beam.sdk.values.PCollectionRowTuple; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; + +public class Managed { + public static final String READ = "READ"; + public static final String WRITE = "WRITE"; + + public enum IO { + ICEBERG Review Comment: Can we do this using discovery instead of listing specific IO connectors. For example, maintain a Schema-Transform pattern within each TransformGroup (for example, `beam:schematransform:read:.*`) and add transforms discovered via AutoValue that maps the pattern. If we cant develop a pattern for a group we can maintain a list. ########## sdks/java/managed/src/main/java/org/apache/beam/sdk/managed/Managed.java: ########## @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.managed; + +import com.google.auto.value.AutoValue; +import java.util.Map; +import javax.annotation.Nullable; +import org.apache.beam.sdk.schemas.transforms.SchemaTransform; +import org.apache.beam.sdk.values.PCollectionRowTuple; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; + +public class Managed { + public static final String READ = "READ"; + public static final String WRITE = "WRITE"; + + public enum IO { + ICEBERG + } + + public static Read read() { + return new AutoValue_Managed_Read.Builder().build(); + } + + @AutoValue + public abstract static class Read extends SchemaTransform { + private final Map<IO, String> identifiers = + ImmutableMap.of(IO.ICEBERG, "beam:schematransform:org.apache.beam:iceberg_read:v1"); + + abstract IO getSource(); + + abstract @Nullable String getConfig(); + + abstract @Nullable String getConfigUrl(); + + abstract Builder toBuilder(); + + @AutoValue.Builder + abstract static class Builder { + abstract Builder setSource(IO source); + + abstract Builder setConfig(String config); + + abstract Builder setConfigUrl(String configUrl); + + abstract Read build(); + } + + public Read from(IO source) { Review Comment: I think this should be `from(String urn)` where `urn` is the schema-transform identifier. ########## sdks/java/managed/src/main/java/org/apache/beam/sdk/managed/ManagedSchemaTransformProvider.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.managed; + +import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkArgument; + +import com.google.auto.service.AutoService; +import com.google.auto.value.AutoValue; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.ServiceLoader; +import java.util.Set; +import javax.annotation.Nullable; +import org.apache.beam.sdk.io.FileSystems; +import org.apache.beam.sdk.schemas.AutoValueSchema; +import org.apache.beam.sdk.schemas.Schema; +import org.apache.beam.sdk.schemas.annotations.DefaultSchema; +import org.apache.beam.sdk.schemas.annotations.SchemaFieldDescription; +import org.apache.beam.sdk.schemas.transforms.SchemaTransform; +import org.apache.beam.sdk.schemas.transforms.SchemaTransformProvider; +import org.apache.beam.sdk.schemas.transforms.TypedSchemaTransformProvider; +import org.apache.beam.sdk.values.PCollectionRowTuple; +import org.apache.beam.sdk.values.Row; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Strings; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Sets; + +@AutoService(SchemaTransformProvider.class) +public class ManagedSchemaTransformProvider + extends TypedSchemaTransformProvider<ManagedSchemaTransformProvider.ManagedConfig> { + + @Override + public String identifier() { + return "beam:schematransform:org.apache.beam:managed:v1"; + } + + private Map<String, SchemaTransformProvider> schemaTransformProviders = new HashMap<>(); + + private ManagedSchemaTransformProvider() { + try { + for (SchemaTransformProvider schemaTransformProvider : + ServiceLoader.load(ManagedSchemaTransformProvider.class)) { Review Comment: We should look for `SchemaTransformProvider`s here not for `ManagedSchemaTransformProvider`s ? (latter is already loaded BTW). ########## sdks/java/managed/src/main/java/org/apache/beam/sdk/managed/Managed.java: ########## @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.managed; + +import com.google.auto.value.AutoValue; +import java.util.Map; +import javax.annotation.Nullable; +import org.apache.beam.sdk.schemas.transforms.SchemaTransform; +import org.apache.beam.sdk.values.PCollectionRowTuple; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; + +public class Managed { + public static final String READ = "READ"; + public static final String WRITE = "WRITE"; + + public enum IO { + ICEBERG + } + + public static Read read() { + return new AutoValue_Managed_Read.Builder().build(); + } + + @AutoValue + public abstract static class Read extends SchemaTransform { + private final Map<IO, String> identifiers = + ImmutableMap.of(IO.ICEBERG, "beam:schematransform:org.apache.beam:iceberg_read:v1"); + + abstract IO getSource(); + + abstract @Nullable String getConfig(); + + abstract @Nullable String getConfigUrl(); + + abstract Builder toBuilder(); + + @AutoValue.Builder + abstract static class Builder { + abstract Builder setSource(IO source); + + abstract Builder setConfig(String config); + + abstract Builder setConfigUrl(String configUrl); + + abstract Read build(); + } + + public Read from(IO source) { + return toBuilder().setSource(source).build(); + } + + public Read withConfigUrl(String configUrl) { + return toBuilder().setConfigUrl(configUrl).build(); + } + + public Read withConfig(String config) { + return toBuilder().setConfigUrl(config).build(); + } + + public Read withConfig(Map<String, Object> config) { + return toBuilder().setConfigUrl(mapToYamlString(config)).build(); Review Comment: `setConfig()`. URL is a URL to download the config. ########## sdks/java/managed/src/main/java/org/apache/beam/sdk/managed/Managed.java: ########## @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.managed; + +import com.google.auto.value.AutoValue; +import java.util.Map; +import javax.annotation.Nullable; +import org.apache.beam.sdk.schemas.transforms.SchemaTransform; +import org.apache.beam.sdk.values.PCollectionRowTuple; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; + +public class Managed { + public static final String READ = "READ"; Review Comment: Probably move this to an enum. Say `TransformGroup`. -- 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]
