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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations