gaoran10 commented on a change in pull request #6325: KeyValue schema support 
for pulsar sql
URL: https://github.com/apache/pulsar/pull/6325#discussion_r379708618
 
 

 ##########
 File path: 
pulsar-sql/presto-pulsar/src/main/java/org/apache/pulsar/sql/presto/PulsarMetadata.java
 ##########
 @@ -398,6 +408,50 @@ private ConnectorTableMetadata 
getTableMetadata(SchemaTableName schemaTableName,
         }
          return builder.build();
     }
+
+    static List<ColumnMetadata> getPulsarColumnsFromKeyValueSchema(TopicName 
topicName,
+                                                                   SchemaInfo 
schemaInfo,
+                                                                   boolean 
withInternalColumns) {
+        ImmutableList.Builder<ColumnMetadata> builder = 
ImmutableList.builder();
+        KeyValue<SchemaInfo, SchemaInfo> kvSchemaInfo = 
KeyValueSchemaInfo.decodeKeyValueSchemaInfo(schemaInfo);
+        SchemaInfo keySchemaInfo = kvSchemaInfo.getKey();
+        List<ColumnMetadata> keyColumnMetadataList = 
getPulsarColumns(topicName, keySchemaInfo, false,
+                true, false);
+        renameColumnName(keyColumnMetadataList, "key.");
+        builder.addAll(keyColumnMetadataList);
+
+        SchemaInfo valueSchemaInfo = kvSchemaInfo.getValue();
+        List<ColumnMetadata> valueColumnMetadataList = 
getPulsarColumns(topicName, valueSchemaInfo, false,
+                false, true);
+        renameColumnName(valueColumnMetadataList, "value.");
+        builder.addAll(valueColumnMetadataList);
+
+        if (withInternalColumns) {
+            PulsarInternalColumn.getInternalFields()
+                    .forEach(pulsarInternalColumn -> 
builder.add(pulsarInternalColumn.getColumnMetadata(false)));
+        }
+        return builder.build();
+    }
+
+    private static void renameColumnName(List<ColumnMetadata> 
columnMetadataList, String namePrefix) {
+        Class<PulsarColumnMetadata> clazz = PulsarColumnMetadata.class;
+        Class<ColumnMetadata> superClazz = ColumnMetadata.class;
+        Field nameField = null;
+        Field nameWithCaseField = null;
+        try {
+            nameField = superClazz.getDeclaredField("name");
+            nameField.setAccessible(true);
+            nameWithCaseField = clazz.getDeclaredField("nameWithCase");
+            nameWithCaseField.setAccessible(true);
+            for (ColumnMetadata columnMetadata : columnMetadataList) {
+                nameField.set(columnMetadata, namePrefix + 
columnMetadata.getName());
+                nameWithCaseField.set(columnMetadata, 
columnMetadata.getName());
+            }
 
 Review comment:
   Good idea!

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to