forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement GenericObject - Allow GenericRecord to wrap any Java Object (…
…apache#10057) Contents: - introduce new high level interface GenericObject, that represents every logical value on the Pulsar topic - allow AutoConsumeSchema to deal with every Schema type - handle schema less topics with AutoConsumeSchema (return Bytes schema and byte[] payload) - rename `getNativeRecord` to `getNativeObject` How it works: - in case of non struct schema, like for primitives and for KeyValue, wrap the result into a PrimitiveRecord class, that is an implementation of GenericRecord that wraps a Object and a SchemaType, it returns an empty list of "fields" Intended audience: - allow users to implement Sink<GenericObject>, that is to write Sinks that work with every Schema type (the patch for Pulsar IO will follow up as a separate PR) ``` interface GenericObject { Object getNativeObject(); SchemaType getSchemaType(); } interface GenericRecord extends GenericObject ```
- Loading branch information
Showing
14 changed files
with
320 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/schema/GenericObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* 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.api.schema; | ||
|
||
import org.apache.pulsar.common.schema.SchemaType; | ||
|
||
/** | ||
* This is an abstraction over the logical value that is store into a Message. | ||
* Pulsar decodes the payload of the Message using the Schema that is configured for the topic. | ||
*/ | ||
public interface GenericObject { | ||
|
||
/** | ||
* Return the schema tyoe. | ||
* | ||
* @return the schema type | ||
* @throws UnsupportedOperationException if this feature is not implemented | ||
* @see SchemaType#BYTES when the topic has no schema information | ||
* @see SchemaType#STRING | ||
* @see SchemaType#AVRO | ||
* @see SchemaType#PROTOBUF_NATIVE | ||
* @see SchemaType#JSON | ||
*/ | ||
SchemaType getSchemaType(); | ||
|
||
/** | ||
* Return the internal native representation of the Object, | ||
* like a AVRO GenericRecord, a String or a byte[]. | ||
* | ||
* @return the decoded object | ||
* @throws UnsupportedOperationException if the operation is not supported | ||
*/ | ||
Object getNativeObject(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.