mirror of
https://github.com/apache/nifi.git
synced 2025-02-09 03:25:04 +00:00
NIFI-7448: Fix quoting of DDL table name in PutORC
Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com> This closes #4269.
This commit is contained in:
parent
9608fe33fa
commit
53a161234e
@ -238,9 +238,11 @@ public class NiFiOrcUtils {
|
||||
}
|
||||
|
||||
public static String generateHiveDDL(RecordSchema recordSchema, String tableName, boolean hiveFieldNames) {
|
||||
StringBuilder sb = new StringBuilder("CREATE EXTERNAL TABLE IF NOT EXISTS `");
|
||||
sb.append(tableName);
|
||||
sb.append("` (");
|
||||
StringBuilder sb = new StringBuilder("CREATE EXTERNAL TABLE IF NOT EXISTS ");
|
||||
String[] tableSections = tableName.split("\\.");
|
||||
String quotedTableName = Arrays.stream(tableSections).map((section) -> "`" + section + "`").collect(Collectors.joining("."));
|
||||
sb.append(quotedTableName);
|
||||
sb.append(" (");
|
||||
List<String> hiveColumns = new ArrayList<>();
|
||||
List<RecordField> fields = recordSchema.getFields();
|
||||
if (fields != null) {
|
||||
|
@ -451,6 +451,29 @@ public class PutORCTest {
|
||||
testRunner.assertAllFlowFilesTransferred(PutORC.REL_SUCCESS, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDDLQuoteTableNameSections() throws IOException, InitializationException {
|
||||
configure(proc, 100);
|
||||
|
||||
final String filename = "testORCWithDefaults-" + System.currentTimeMillis();
|
||||
|
||||
final Map<String, String> flowFileAttributes = new HashMap<>();
|
||||
flowFileAttributes.put(CoreAttributes.FILENAME.key(), filename);
|
||||
|
||||
testRunner.setProperty(PutORC.HIVE_TABLE_NAME, "mydb.myTable");
|
||||
|
||||
testRunner.enqueue("trigger", flowFileAttributes);
|
||||
testRunner.run();
|
||||
testRunner.assertAllFlowFilesTransferred(PutORC.REL_SUCCESS, 1);
|
||||
|
||||
final Path orcFile = new Path(DIRECTORY + "/" + filename);
|
||||
|
||||
// verify the successful flow file has the expected attributes
|
||||
final MockFlowFile mockFlowFile = testRunner.getFlowFilesForRelationship(PutORC.REL_SUCCESS).get(0);
|
||||
mockFlowFile.assertAttributeEquals(PutORC.HIVE_DDL_ATTRIBUTE,
|
||||
"CREATE EXTERNAL TABLE IF NOT EXISTS `mydb`.`myTable` (`name` STRING, `favorite_number` INT, `favorite_color` STRING, `scale` DOUBLE) STORED AS ORC");
|
||||
}
|
||||
|
||||
private void verifyORCUsers(final Path orcUsers, final int numExpectedUsers) throws IOException {
|
||||
verifyORCUsers(orcUsers, numExpectedUsers, null);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user