Search in sources :

Example 1 with PulsarColumnMetadata

use of org.apache.pulsar.sql.presto.PulsarColumnMetadata in project pulsar by apache.

the class AbstractDecoderTester method getColumnColumnHandles.

protected List<PulsarColumnHandle> getColumnColumnHandles(TopicName topicName, SchemaInfo schemaInfo, PulsarColumnHandle.HandleKeyValueType handleKeyValueType, boolean includeInternalColumn, PulsarDispatchingRowDecoderFactory dispatchingRowDecoderFactory) {
    List<PulsarColumnHandle> columnHandles = new ArrayList<>();
    List<ColumnMetadata> columnMetadata = pulsarMetadata.getPulsarColumns(topicName, schemaInfo, includeInternalColumn, handleKeyValueType);
    columnMetadata.forEach(column -> {
        PulsarColumnMetadata pulsarColumnMetadata = (PulsarColumnMetadata) column;
        columnHandles.add(new PulsarColumnHandle(pulsarConnectorId.toString(), pulsarColumnMetadata.getNameWithCase(), pulsarColumnMetadata.getType(), pulsarColumnMetadata.isHidden(), pulsarColumnMetadata.isInternal(), pulsarColumnMetadata.getDecoderExtraInfo().getMapping(), pulsarColumnMetadata.getDecoderExtraInfo().getDataFormat(), pulsarColumnMetadata.getDecoderExtraInfo().getFormatHint(), pulsarColumnMetadata.getHandleKeyValueType()));
    });
    return columnHandles;
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) PulsarColumnMetadata(org.apache.pulsar.sql.presto.PulsarColumnMetadata) ArrayList(java.util.ArrayList) PulsarColumnHandle(org.apache.pulsar.sql.presto.PulsarColumnHandle) PulsarColumnMetadata(org.apache.pulsar.sql.presto.PulsarColumnMetadata)

Example 2 with PulsarColumnMetadata

use of org.apache.pulsar.sql.presto.PulsarColumnMetadata in project pulsar by apache.

the class PulsarAvroRowDecoderFactory method extractColumnMetadata.

@Override
public List<ColumnMetadata> extractColumnMetadata(TopicName topicName, SchemaInfo schemaInfo, PulsarColumnHandle.HandleKeyValueType handleKeyValueType) {
    List<ColumnMetadata> columnMetadata;
    String schemaJson = new String(schemaInfo.getSchema());
    if (StringUtils.isBlank(schemaJson)) {
        throw new PrestoException(NOT_SUPPORTED, "Topic " + topicName.toString() + " does not have a valid schema");
    }
    Schema schema;
    try {
        schema = GenericJsonSchema.of(schemaInfo).getAvroSchema();
    } catch (SchemaParseException ex) {
        throw new PrestoException(NOT_SUPPORTED, "Topic " + topicName.toString() + " does not have a valid schema");
    }
    try {
        columnMetadata = schema.getFields().stream().map(field -> new PulsarColumnMetadata(PulsarColumnMetadata.getColumnName(handleKeyValueType, field.name()), parseAvroPrestoType(field.name(), field.schema()), field.schema().toString(), null, false, false, handleKeyValueType, new PulsarColumnMetadata.DecoderExtraInfo(field.name(), null, null))).collect(toList());
    } catch (StackOverflowError e) {
        log.warn(e, "Topic " + topicName.toString() + " extractColumnMetadata failed.");
        throw new PrestoException(NOT_SUPPORTED, "Topic " + topicName.toString() + " schema may contains cyclic definitions.", e);
    }
    return columnMetadata;
}
Also used : PulsarColumnMetadata(org.apache.pulsar.sql.presto.PulsarColumnMetadata) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) SchemaParseException(org.apache.avro.SchemaParseException) Schema(org.apache.avro.Schema) GenericJsonSchema(org.apache.pulsar.client.impl.schema.generic.GenericJsonSchema) GenericAvroSchema(org.apache.pulsar.client.impl.schema.generic.GenericAvroSchema) PrestoException(io.prestosql.spi.PrestoException) PulsarColumnMetadata(org.apache.pulsar.sql.presto.PulsarColumnMetadata)

Example 3 with PulsarColumnMetadata

use of org.apache.pulsar.sql.presto.PulsarColumnMetadata in project pulsar by yahoo.

the class AbstractDecoderTester method getColumnColumnHandles.

protected List<PulsarColumnHandle> getColumnColumnHandles(TopicName topicName, SchemaInfo schemaInfo, PulsarColumnHandle.HandleKeyValueType handleKeyValueType, boolean includeInternalColumn, PulsarDispatchingRowDecoderFactory dispatchingRowDecoderFactory) {
    List<PulsarColumnHandle> columnHandles = new ArrayList<>();
    List<ColumnMetadata> columnMetadata = pulsarMetadata.getPulsarColumns(topicName, schemaInfo, includeInternalColumn, handleKeyValueType);
    columnMetadata.forEach(column -> {
        PulsarColumnMetadata pulsarColumnMetadata = (PulsarColumnMetadata) column;
        columnHandles.add(new PulsarColumnHandle(pulsarConnectorId.toString(), pulsarColumnMetadata.getNameWithCase(), pulsarColumnMetadata.getType(), pulsarColumnMetadata.isHidden(), pulsarColumnMetadata.isInternal(), pulsarColumnMetadata.getDecoderExtraInfo().getMapping(), pulsarColumnMetadata.getDecoderExtraInfo().getDataFormat(), pulsarColumnMetadata.getDecoderExtraInfo().getFormatHint(), pulsarColumnMetadata.getHandleKeyValueType()));
    });
    return columnHandles;
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) PulsarColumnMetadata(org.apache.pulsar.sql.presto.PulsarColumnMetadata) ArrayList(java.util.ArrayList) PulsarColumnHandle(org.apache.pulsar.sql.presto.PulsarColumnHandle) PulsarColumnMetadata(org.apache.pulsar.sql.presto.PulsarColumnMetadata)

Example 4 with PulsarColumnMetadata

use of org.apache.pulsar.sql.presto.PulsarColumnMetadata in project pulsar by yahoo.

the class PulsarProtobufNativeRowDecoderFactory method extractColumnMetadata.

@Override
public List<ColumnMetadata> extractColumnMetadata(TopicName topicName, SchemaInfo schemaInfo, PulsarColumnHandle.HandleKeyValueType handleKeyValueType) {
    List<ColumnMetadata> columnMetadata;
    String schemaJson = new String(schemaInfo.getSchema());
    if (StringUtils.isBlank(schemaJson)) {
        throw new PrestoException(NOT_SUPPORTED, "Topic " + topicName.toString() + " does not have a valid schema");
    }
    Descriptors.Descriptor schema;
    try {
        schema = ((GenericProtobufNativeSchema) GenericProtobufNativeSchema.of(schemaInfo)).getProtobufNativeSchema();
    } catch (Exception ex) {
        log.error(ex);
        throw new PrestoException(NOT_SUPPORTED, "Topic " + topicName.toString() + " does not have a valid schema");
    }
    // Protobuf have not yet supported Cyclic Objects.
    columnMetadata = schema.getFields().stream().map(field -> new PulsarColumnMetadata(PulsarColumnMetadata.getColumnName(handleKeyValueType, field.getName()), parseProtobufPrestoType(field), field.getType().toString(), null, false, false, handleKeyValueType, new PulsarColumnMetadata.DecoderExtraInfo(field.getName(), null, null))).collect(toList());
    return columnMetadata;
}
Also used : PulsarColumnMetadata(org.apache.pulsar.sql.presto.PulsarColumnMetadata) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) PrestoException(io.prestosql.spi.PrestoException) Descriptors(com.google.protobuf.Descriptors) PrestoException(io.prestosql.spi.PrestoException) PulsarColumnMetadata(org.apache.pulsar.sql.presto.PulsarColumnMetadata)

Example 5 with PulsarColumnMetadata

use of org.apache.pulsar.sql.presto.PulsarColumnMetadata in project pulsar by apache.

the class PulsarJsonRowDecoderFactory method extractColumnMetadata.

@Override
public List<ColumnMetadata> extractColumnMetadata(TopicName topicName, SchemaInfo schemaInfo, PulsarColumnHandle.HandleKeyValueType handleKeyValueType) {
    List<ColumnMetadata> columnMetadata;
    String schemaJson = new String(schemaInfo.getSchema());
    if (StringUtils.isBlank(schemaJson)) {
        throw new PrestoException(NOT_SUPPORTED, "Topic " + topicName.toString() + " does not have a valid schema");
    }
    Schema schema;
    try {
        schema = GenericJsonSchema.of(schemaInfo).getAvroSchema();
    } catch (SchemaParseException ex) {
        throw new PrestoException(NOT_SUPPORTED, "Topic " + topicName.toString() + " does not have a valid schema");
    }
    try {
        columnMetadata = schema.getFields().stream().map(field -> new PulsarColumnMetadata(PulsarColumnMetadata.getColumnName(handleKeyValueType, field.name()), parseJsonPrestoType(field.name(), field.schema()), field.schema().toString(), null, false, false, handleKeyValueType, new PulsarColumnMetadata.DecoderExtraInfo(field.name(), null, null))).collect(toList());
    } catch (StackOverflowError e) {
        log.warn(e, "Topic " + topicName.toString() + " extractColumnMetadata failed.");
        throw new PrestoException(NOT_SUPPORTED, "Topic " + topicName.toString() + " schema may contains cyclic definitions.", e);
    }
    return columnMetadata;
}
Also used : PulsarColumnMetadata(org.apache.pulsar.sql.presto.PulsarColumnMetadata) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) SchemaParseException(org.apache.avro.SchemaParseException) Schema(org.apache.avro.Schema) GenericJsonSchema(org.apache.pulsar.client.impl.schema.generic.GenericJsonSchema) PrestoException(io.prestosql.spi.PrestoException) PulsarColumnMetadata(org.apache.pulsar.sql.presto.PulsarColumnMetadata)

Aggregations

ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)8 PulsarColumnMetadata (org.apache.pulsar.sql.presto.PulsarColumnMetadata)8 PrestoException (io.prestosql.spi.PrestoException)6 Schema (org.apache.avro.Schema)4 SchemaParseException (org.apache.avro.SchemaParseException)4 GenericJsonSchema (org.apache.pulsar.client.impl.schema.generic.GenericJsonSchema)4 Descriptors (com.google.protobuf.Descriptors)2 ArrayList (java.util.ArrayList)2 GenericAvroSchema (org.apache.pulsar.client.impl.schema.generic.GenericAvroSchema)2 PulsarColumnHandle (org.apache.pulsar.sql.presto.PulsarColumnHandle)2