eolivelli commented on a change in pull request #11238:
URL: https://github.com/apache/pulsar/pull/11238#discussion_r665201011



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoProduceValidatedAvroBytesSchema.java
##########
@@ -0,0 +1,75 @@
+/**
+ * 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.pulsar.client.impl.schema;
+
+import static com.google.common.base.Preconditions.checkState;
+
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.schema.SchemaDefinition;
+import org.apache.pulsar.client.internal.DefaultImplementation;
+import org.apache.pulsar.common.schema.SchemaInfo;
+import org.apache.pulsar.common.schema.SchemaType;
+
+import java.util.Optional;
+
+/**
+ * Auto detect schema.

Review comment:
       This comment is wrong

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoProduceValidatedAvroBytesSchema.java
##########
@@ -0,0 +1,75 @@
+/**
+ * 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.pulsar.client.impl.schema;
+
+import static com.google.common.base.Preconditions.checkState;
+
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.schema.SchemaDefinition;
+import org.apache.pulsar.client.internal.DefaultImplementation;
+import org.apache.pulsar.common.schema.SchemaInfo;
+import org.apache.pulsar.common.schema.SchemaType;
+
+import java.util.Optional;
+
+/**
+ * Auto detect schema.
+ */
+public class AutoProduceValidatedAvroBytesSchema<T> extends 
AutoProduceBytesSchema<T> {
+
+    private Schema<T> schema;
+
+    
+    public AutoProduceValidatedAvroBytesSchema(org.apache.avro.Schema schema) {
+        SchemaDefinition schemaDefinition = 
SchemaDefinition.builder().withJsonDef(schema.toString(false)).build();
+        
+        setSchema(DefaultImplementation.newAvroSchema(schemaDefinition));
+    }
+
+    public AutoProduceValidatedAvroBytesSchema(Schema<T> schema) {
+        this.schema = null;

Review comment:
       why do you need to set this to `null` if you are setting it in the line 
below ?

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoProduceValidatedAvroBytesSchema.java
##########
@@ -0,0 +1,75 @@
+/**
+ * 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.pulsar.client.impl.schema;
+
+import static com.google.common.base.Preconditions.checkState;
+
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.schema.SchemaDefinition;
+import org.apache.pulsar.client.internal.DefaultImplementation;
+import org.apache.pulsar.common.schema.SchemaInfo;
+import org.apache.pulsar.common.schema.SchemaType;
+
+import java.util.Optional;
+
+/**
+ * Auto detect schema.
+ */
+public class AutoProduceValidatedAvroBytesSchema<T> extends 
AutoProduceBytesSchema<T> {
+
+    private Schema<T> schema;
+
+    
+    public AutoProduceValidatedAvroBytesSchema(org.apache.avro.Schema schema) {
+        SchemaDefinition schemaDefinition = 
SchemaDefinition.builder().withJsonDef(schema.toString(false)).build();
+        
+        setSchema(DefaultImplementation.newAvroSchema(schemaDefinition));

Review comment:
       here we are inside the "impl" package.
   So we must not use DefaultImplementation, use directly the AvroSchema 
constructor

##########
File path: 
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/Schema.java
##########
@@ -426,6 +426,19 @@ default void configureSchemaInfo(String topic, String 
componentName,
         return DefaultImplementation.newAutoProduceSchema(schema);
     }
 
+    /**
+     * Create a schema instance that accepts a serialized Avro payload
+     * without validating it against the schema specified. 
+     * It can be useful when migrating data from existing event or message 
stores.
+     *
+     * @return the auto schema instance
+     * @since 2.9.0
+     * @see #AUTO_PRODUCE_BYTES()
+     */
+    static Schema<byte[]> AUTO_PRODUCE_VALIDATED_AVRO_BYTES(Schema<?> schema) {
+        return DefaultImplementation.newAutoProduceValidatedAvroSchema(schema);

Review comment:
       IIUC this "schema" is a "org.apache.avro.Schema"
   
   so you have to declare your method as:
   `static Schema<byte[]> AUTO_PRODUCE_VALIDATED_AVRO_BYTES(Object 
nativeAvroSchema)`
   you can do the Cast inside AutoProduceValidatedAvroBytesSchema in which you 
will have the constructor like
   
   ```
   AutoProduceValidatedAvroBytesSchema(Object schema) {
      if (! schema instanceof org.apache.avro.Schema) throw new 
IllegalArgumentException...
   }
   ```
   
   I suggest to rename the method to   `Schema<byte[]> NATIVE_AVRO(Object 
schema)`




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