Skip to content

Commit

Permalink
Cloned trinodb/trino trinodb#8020
Browse files Browse the repository at this point in the history
More fixes
  • Loading branch information
eaba committed Sep 21, 2024
1 parent 125f0a3 commit 2ce0c67
Show file tree
Hide file tree
Showing 64 changed files with 8,221 additions and 12,036 deletions.
278 changes: 64 additions & 214 deletions plugin/trino-pulsar/pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,80 +1,73 @@
/*
* 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
* Licensed 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
* 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.
* 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 io.trino.plugin.pulsar;

import static java.util.Objects.requireNonNull;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.trino.decoder.DecoderColumnHandle;
import io.trino.spi.connector.ColumnMetadata;
import io.trino.spi.type.Type;
import java.util.Objects;

/**
* This class represents the basic information about a presto column.
*/
public class PulsarColumnHandle implements DecoderColumnHandle {
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import static com.google.common.base.MoreObjects.toStringHelper;
import static io.trino.plugin.pulsar.PulsarColumnMetadata.PROPERTY_KEY_DATA_FORMAT;
import static io.trino.plugin.pulsar.PulsarColumnMetadata.PROPERTY_KEY_FORMAT_HINT;
import static io.trino.plugin.pulsar.PulsarColumnMetadata.PROPERTY_KEY_HANDLE_TYPE;
import static io.trino.plugin.pulsar.PulsarColumnMetadata.PROPERTY_KEY_INTERNAL;
import static io.trino.plugin.pulsar.PulsarColumnMetadata.PROPERTY_KEY_MAPPING;
import static io.trino.plugin.pulsar.PulsarColumnMetadata.PROPERTY_KEY_NAME_CASE_SENSITIVE;
import static java.util.Objects.requireNonNull;

private final String connectorId;
public class PulsarColumnHandle
implements DecoderColumnHandle
{
private final String catalogName;

/**
* Column Name.
*/
private final String name;

/**
* Column type.
*/
private final Type type;

/**
* True if the column should be hidden.
*/
private final boolean hidden;

/**
* True if the column is internal to the connector and not defined by a topic definition.
*/
private final boolean internal;


private HandleKeyValueType handleKeyValueType;

/**
* {@link io.trino.plugin.pulsar.PulsarColumnMetadata.DecoderExtraInfo#mapping}.
* {@link PulsarColumnMetadata.DecoderExtraInfo#mapping}.
*/
private String mapping;
/**
* {@link io.trino.plugin.pulsar.PulsarColumnMetadata.DecoderExtraInfo#dataFormat}.
* {@link PulsarColumnMetadata.DecoderExtraInfo#dataFormat}.
*/
private String dataFormat;

/**
* {@link io.trino.plugin.pulsar.PulsarColumnMetadata.DecoderExtraInfo#formatHint}.
* {@link PulsarColumnMetadata.DecoderExtraInfo#formatHint}.
*/
private String formatHint;

/**
* Column Handle keyValue type, used for keyValue schema.
*/
public enum HandleKeyValueType {
public enum HandleKeyValueType
{
/**
* The handle not for keyValue schema.
*/
Expand All @@ -91,157 +84,156 @@ public enum HandleKeyValueType {

@JsonCreator
public PulsarColumnHandle(
@JsonProperty("connectorId") String connectorId,
@JsonProperty("catalogName") String catalogName,
@JsonProperty("name") String name,
@JsonProperty("type") Type type,
@JsonProperty("hidden") boolean hidden,
@JsonProperty("internal") boolean internal,
@JsonProperty("mapping") String mapping,
@JsonProperty("dataFormat") String dataFormat,
@JsonProperty("formatHint") String formatHint,
@JsonProperty("handleKeyValueType") HandleKeyValueType handleKeyValueType) {
this.connectorId = requireNonNull(connectorId, "connectorId is null");
@JsonProperty("handleKeyValueType") Optional<HandleKeyValueType> handleKeyValueType)
{
this.catalogName = requireNonNull(catalogName, "catalogName is null");
this.name = requireNonNull(name, "name is null");
this.type = requireNonNull(type, "type is null");
this.hidden = hidden;
this.internal = internal;
this.mapping = mapping;
this.dataFormat = dataFormat;
this.formatHint = formatHint;
if (handleKeyValueType == null) {
this.handleKeyValueType = HandleKeyValueType.NONE;
} else {
this.handleKeyValueType = handleKeyValueType;
}
this.handleKeyValueType = handleKeyValueType.isPresent() ? handleKeyValueType.get() : HandleKeyValueType.NONE;
}

@JsonProperty
public String getConnectorId() {
return connectorId;
public String getCatalogName()
{
return catalogName;
}

@Override
@JsonProperty
public String getName() {
public String getName()
{
return name;
}

@Override
@JsonProperty
public String getMapping() {
public String getMapping()
{
return mapping;
}

@Override
@JsonProperty
public String getDataFormat() {
public String getDataFormat()
{
return dataFormat;
}

@Override
@JsonProperty
public Type getType() {
public Type getType()
{
return type;
}

@JsonProperty
public boolean isHidden() {
public boolean isHidden()
{
return hidden;
}

@Override
@JsonProperty
public boolean isInternal() {
public boolean isInternal()
{
return internal;
}

@Override
@JsonProperty
public String getFormatHint() {
public String getFormatHint()
{
return formatHint;
}

@JsonProperty
public HandleKeyValueType getHandleKeyValueType() {
public HandleKeyValueType getHandleKeyValueType()
{
return handleKeyValueType;
}

@JsonIgnore
public boolean isKey() {
public boolean isKey()
{
return Objects.equals(handleKeyValueType, HandleKeyValueType.KEY);
}

@JsonIgnore
public boolean isValue() {
public boolean isValue()
{
return Objects.equals(handleKeyValueType, HandleKeyValueType.VALUE);
}

ColumnMetadata getColumnMetadata() {
return new PulsarColumnMetadata(name, type, null, null, hidden,
internal, handleKeyValueType, new PulsarColumnMetadata.DecoderExtraInfo(
mapping, dataFormat, formatHint));
ColumnMetadata getColumnMetadata()
{
Map<String, Object> properties = new HashMap<>();
properties.put(PROPERTY_KEY_NAME_CASE_SENSITIVE, name);
properties.put(PROPERTY_KEY_INTERNAL, internal);
properties.put(PROPERTY_KEY_HANDLE_TYPE, handleKeyValueType);
properties.put(PROPERTY_KEY_MAPPING, mapping);
properties.put(PROPERTY_KEY_DATA_FORMAT, dataFormat);
properties.put(PROPERTY_KEY_FORMAT_HINT, formatHint);
return ColumnMetadata.builder()
.setName(name)
.setType(type)
.setHidden(hidden)
.setProperties(properties)
.build();
}

@Override
public boolean equals(Object o) {
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof PulsarColumnHandle)) {
return false;
}

PulsarColumnHandle that = (PulsarColumnHandle) o;

if (hidden != that.hidden) {
return false;
}
if (internal != that.internal) {
return false;
}
if (connectorId != null ? !connectorId.equals(that.connectorId) : that.connectorId != null) {
return false;
}
if (name != null ? !name.equals(that.name) : that.name != null) {
return false;
}
if (type != null ? !type.equals(that.type) : that.type != null) {
return false;
}
if (mapping != null ? !mapping.equals(that.mapping) : that.mapping != null) {
return false;
}
if (dataFormat != null ? !dataFormat.equals(that.dataFormat) : that.dataFormat != null) {
return false;
}

if (formatHint != null ? !formatHint.equals(that.formatHint) : that.formatHint != null) {
return false;
}

return Objects.equals(handleKeyValueType, that.handleKeyValueType);
return isHidden() == that.isHidden() &&
isInternal() == that.isInternal() &&
Objects.equals(getCatalogName(), that.getCatalogName()) &&
Objects.equals(getName(), that.getName()) &&
Objects.equals(getType(), that.getType()) &&
getHandleKeyValueType() == that.getHandleKeyValueType() &&
Objects.equals(getMapping(), that.getMapping()) &&
Objects.equals(getDataFormat(), that.getDataFormat()) &&
Objects.equals(getFormatHint(), that.getFormatHint());
}

@Override
public int hashCode() {
int result = connectorId != null ? connectorId.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (type != null ? type.hashCode() : 0);
result = 31 * result + (hidden ? 1 : 0);
result = 31 * result + (internal ? 1 : 0);
result = 31 * result + (mapping != null ? mapping.hashCode() : 0);
result = 31 * result + (dataFormat != null ? dataFormat.hashCode() : 0);
result = 31 * result + (formatHint != null ? formatHint.hashCode() : 0);
result = 31 * result + (handleKeyValueType != null ? handleKeyValueType.hashCode() : 0);
return result;
public int hashCode()
{
return Objects.hash(getCatalogName(), getName(), getType(), isHidden(), isInternal(), getHandleKeyValueType(), getMapping(), getDataFormat(), getFormatHint());
}

@Override
public String toString() {
return "PulsarColumnHandle{"
+ "connectorId='" + connectorId + '\''
+ ", name='" + name + '\''
+ ", type=" + type
+ ", hidden=" + hidden
+ ", internal=" + internal
+ ", mapping=" + mapping
+ ", dataFormat=" + dataFormat
+ ", formatHint=" + formatHint
+ ", handleKeyValueType=" + handleKeyValueType
+ '}';
public String toString()
{
return toStringHelper(this)
.add("catalogName", catalogName)
.add("name", name)
.add("type", type)
.add("hidden", hidden)
.add("internal", internal)
.add("handleKeyValueType", handleKeyValueType)
.add("mapping", mapping)
.add("dataFormat", dataFormat)
.add("formatHint", formatHint)
.toString();
}
}
Loading

0 comments on commit 2ce0c67

Please # to comment.