@@ -21,6 +21,10 @@ module.exports = (baseProvider, options, app) => {
2121 setOrReplace,
2222 getCompositeName,
2323 toString,
24+ parseTextArea,
25+ parseProps,
26+ getRowFormat,
27+ getStoredAs,
2428 } = require ( './helpers/general' ) ( app ) ;
2529 const {
2630 decorateType,
@@ -34,6 +38,49 @@ module.exports = (baseProvider, options, app) => {
3438 } = require ( './helpers/columnDefinitionHelper' ) ( app ) ;
3539 const { generateConstraint } = require ( './helpers/constraintHelper' ) ( app ) ;
3640
41+ const buildExternalTable = ( { tableData, schemaName, asSelect, isActivated, comment, columnDescriptions } ) => {
42+ const partitionedBy = tableData . partitionedBy
43+ ? `\nPARTITIONED BY (${ parseTextArea ( tableData . partitionedBy ) } )`
44+ : '' ;
45+
46+ const rowFormat = getRowFormat ( tableData ) ;
47+ const storedAs = getStoredAs ( tableData ) ;
48+
49+ const location = tableData . externalLocation ? `\nLOCATION ${ toString ( tableData . externalLocation ) } ` : '' ;
50+ const tblProperties = tableData . tableProperties
51+ ? `\nTABLE PROPERTIES (${ parseProps ( tableData . tableProperties ) } )`
52+ : '' ;
53+ const columnDefinitions = getColumnsDefinitions ( tableData . columns , isActivated ) ;
54+
55+ if ( asSelect ) {
56+ return assignTemplates ( templates . createExternalTableAs , {
57+ name : tableData . name ,
58+ schemaName,
59+ partitionedBy,
60+ rowFormat,
61+ storedAs,
62+ location,
63+ tableProperties : tblProperties ,
64+ query : asSelect ,
65+ comment : tableData . comment ? comment : '' ,
66+ columnDescriptions,
67+ } ) ;
68+ }
69+
70+ return assignTemplates ( templates . createExternalTable , {
71+ name : tableData . name ,
72+ schemaName,
73+ columnDefinitions : columnDefinitions === '' ? '' : '\n\t' + columnDefinitions ,
74+ partitionedBy,
75+ rowFormat,
76+ storedAs,
77+ location,
78+ tableProperties : tblProperties ,
79+ comment : tableData . comment ? comment : '' ,
80+ columnDescriptions,
81+ } ) ;
82+ } ;
83+
3784 return {
3885 createSchema ( {
3986 name,
@@ -107,6 +154,17 @@ module.exports = (baseProvider, options, app) => {
107154 tableData . columnDefinitions ,
108155 ) ;
109156
157+ if ( tableData . externalTable ) {
158+ return buildExternalTable ( {
159+ tableData,
160+ schemaName,
161+ asSelect,
162+ isActivated,
163+ comment,
164+ columnDescriptions,
165+ } ) ;
166+ }
167+
110168 if ( asSelect ) {
111169 return assignTemplates ( templates . createTableAs , {
112170 name : tableData . name ,
@@ -338,6 +396,17 @@ module.exports = (baseProvider, options, app) => {
338396 ? ''
339397 : generateConstraint ( sortKey , templates . compoundSortKey , jsonSchema . isActivated , { sortStyle } ) ,
340398 query : '' ,
399+ externalTable : firstTab . externalTable ,
400+ partitionedBy : firstTab . partitionedBy ,
401+ rowFormatType : firstTab . rowFormatType ,
402+ rowFormatDelimited : firstTab . rowFormatDelimited ,
403+ rowFormatSerde : firstTab . rowFormatSerde ,
404+ serdeProperties : firstTab . serdeProperties ,
405+ storedAs : firstTab . storedAs ,
406+ inputFormatClass : firstTab . inputFormatClass ,
407+ outputFormatClass : firstTab . outputFormatClass ,
408+ externalLocation : firstTab . externalLocation ,
409+ tableProperties : firstTab . tableProperties ,
341410 } ;
342411 } ,
343412
0 commit comments