@@ -76,75 +76,77 @@ public Boolean buildOutDefinition(TableMirror tableMirror) throws RequiredConfig
76
76
77
77
copySpec = new CopySpec (tableMirror , Environment .LEFT , Environment .RIGHT );
78
78
// Can't LINK ACID tables.
79
- if (TableUtils .isHiveNative (let ) && !TableUtils .isACID (let )) {
80
- // For COMMON, we're assuming the namespace is used by 'both' so we don't change anything..
81
- copySpec .setReplaceLocation (Boolean .FALSE );
82
- if (hmsMirrorConfig .convertManaged ())
83
- copySpec .setUpgrade (Boolean .TRUE );
84
- // COMMON owns the data unless readonly specified.
85
- if (!hmsMirrorConfig .isReadOnly ())
86
- copySpec .setTakeOwnership (Boolean .TRUE );
87
- if (hmsMirrorConfig .isNoPurge ())
88
- copySpec .setTakeOwnership (Boolean .FALSE );
79
+ if (let .isExists ()) {
80
+ if (TableUtils .isHiveNative (let ) && !TableUtils .isACID (let )) {
81
+ // For COMMON, we're assuming the namespace is used by 'both' so we don't change anything..
82
+ copySpec .setReplaceLocation (Boolean .FALSE );
83
+ if (hmsMirrorConfig .convertManaged ())
84
+ copySpec .setUpgrade (Boolean .TRUE );
85
+ // COMMON owns the data unless readonly specified.
86
+ if (!hmsMirrorConfig .isReadOnly ())
87
+ copySpec .setTakeOwnership (Boolean .TRUE );
88
+ if (hmsMirrorConfig .isNoPurge ())
89
+ copySpec .setTakeOwnership (Boolean .FALSE );
89
90
90
- if (hmsMirrorConfig .isSync ()) {
91
- // We assume that the 'definitions' are only there if the
92
- // table exists.
93
- if (!let .isExists () && ret .isExists ()) {
94
- // If left is empty and right is not, DROP RIGHT.
95
- ret .addIssue ("Schema doesn't exist in 'source'. Will be DROPPED." );
96
- ret .setCreateStrategy (CreateStrategy .DROP );
97
- } else if (let .isExists () && !ret .isExists ()) {
98
- // If left is defined and right is not, CREATE RIGHT.
99
- ret .addIssue ("Schema missing, will be CREATED" );
100
- ret .setCreateStrategy (CreateStrategy .CREATE );
101
- } else if (let .isExists () && ret .isExists ()) {
102
- // If left and right, check schema change and replace if necessary.
103
- // Compare Schemas.
104
- if (tableMirror .schemasEqual (Environment .LEFT , Environment .RIGHT )) {
91
+ if (hmsMirrorConfig .isSync ()) {
92
+ // We assume that the 'definitions' are only there if the
93
+ // table exists.
94
+ if (let .isExists () && !ret .isExists ()) {
95
+ // If left is defined and right is not, CREATE RIGHT.
96
+ ret .addIssue ("Schema missing, will be CREATED" );
97
+ ret .setCreateStrategy (CreateStrategy .CREATE );
98
+ } else if (let .isExists () && ret .isExists ()) {
99
+ // If left and right, check schema change and replace if necessary.
100
+ // Compare Schemas.
101
+ if (tableMirror .schemasEqual (Environment .LEFT , Environment .RIGHT )) {
102
+ ret .addIssue (SCHEMA_EXISTS_NO_ACTION_DATA .getDesc ());
103
+ ret .addSql (SKIPPED .getDesc (), "-- " + SCHEMA_EXISTS_NO_ACTION_DATA .getDesc ());
104
+ ret .setCreateStrategy (CreateStrategy .LEAVE );
105
+ String msg = MessageFormat .format (TABLE_ISSUE .getDesc (), tableMirror .getParent ().getName (), tableMirror .getName (),
106
+ SCHEMA_EXISTS_NO_ACTION_DATA .getDesc ());
107
+ log .error (msg );
108
+ } else {
109
+ if (TableUtils .isExternalPurge (ret )) {
110
+ ret .addIssue (SCHEMA_EXISTS_NOT_MATCH_WITH_PURGE .getDesc ());
111
+ ret .addSql (SKIPPED .getDesc (), "-- " + SCHEMA_EXISTS_NOT_MATCH_WITH_PURGE .getDesc ());
112
+ ret .setCreateStrategy (CreateStrategy .LEAVE );
113
+ String msg = MessageFormat .format (TABLE_ISSUE .getDesc (), tableMirror .getParent ().getName (), tableMirror .getName (),
114
+ SCHEMA_EXISTS_NOT_MATCH_WITH_PURGE .getDesc ());
115
+ log .error (msg );
116
+ return Boolean .FALSE ;
117
+ } else {
118
+ ret .addIssue ("Schema exists AND DOESN'T match. It will be REPLACED (DROPPED and RECREATED)." );
119
+ ret .setCreateStrategy (CreateStrategy .REPLACE );
120
+ }
121
+ }
122
+ }
123
+ // With sync, don't own data.
124
+ copySpec .setTakeOwnership (Boolean .FALSE );
125
+ } else {
126
+ if (ret .isExists ()) {
127
+ // Already exists, no action.
105
128
ret .addIssue (SCHEMA_EXISTS_NO_ACTION_DATA .getDesc ());
106
129
ret .addSql (SKIPPED .getDesc (), "-- " + SCHEMA_EXISTS_NO_ACTION_DATA .getDesc ());
107
130
ret .setCreateStrategy (CreateStrategy .LEAVE );
108
131
String msg = MessageFormat .format (TABLE_ISSUE .getDesc (), tableMirror .getParent ().getName (), tableMirror .getName (),
109
132
SCHEMA_EXISTS_NO_ACTION_DATA .getDesc ());
110
133
log .error (msg );
134
+ return Boolean .FALSE ;
111
135
} else {
112
- if (TableUtils .isExternalPurge (ret )) {
113
- ret .addIssue (SCHEMA_EXISTS_NOT_MATCH_WITH_PURGE .getDesc ());
114
- ret .addSql (SKIPPED .getDesc (), "-- " + SCHEMA_EXISTS_NOT_MATCH_WITH_PURGE .getDesc ());
115
- ret .setCreateStrategy (CreateStrategy .LEAVE );
116
- String msg = MessageFormat .format (TABLE_ISSUE .getDesc (), tableMirror .getParent ().getName (), tableMirror .getName (),
117
- SCHEMA_EXISTS_NOT_MATCH_WITH_PURGE .getDesc ());
118
- log .error (msg );
119
- return Boolean .FALSE ;
120
- } else {
121
- ret .addIssue ("Schema exists AND DOESN'T match. It will be REPLACED (DROPPED and RECREATED)." );
122
- ret .setCreateStrategy (CreateStrategy .REPLACE );
123
- }
136
+ ret .addIssue ("Schema will be created" );
137
+ ret .setCreateStrategy (CreateStrategy .CREATE );
124
138
}
125
139
}
126
- // With sync, don't own data .
127
- copySpec . setTakeOwnership ( Boolean . FALSE );
140
+ // Rebuild Target from Source .
141
+ rtn = buildTableSchema ( copySpec );
128
142
} else {
129
- if (ret .isExists ()) {
130
- // Already exists, no action.
131
- ret .addIssue (SCHEMA_EXISTS_NO_ACTION_DATA .getDesc ());
132
- ret .addSql (SKIPPED .getDesc (), "-- " + SCHEMA_EXISTS_NO_ACTION_DATA .getDesc ());
133
- ret .setCreateStrategy (CreateStrategy .LEAVE );
134
- String msg = MessageFormat .format (TABLE_ISSUE .getDesc (), tableMirror .getParent ().getName (), tableMirror .getName (),
135
- SCHEMA_EXISTS_NO_ACTION_DATA .getDesc ());
136
- log .error (msg );
137
- return Boolean .FALSE ;
138
- } else {
139
- ret .addIssue ("Schema will be created" );
140
- ret .setCreateStrategy (CreateStrategy .CREATE );
141
- }
143
+ let .addIssue ("Can't use COMMON for ACID tables" );
144
+ ret .setCreateStrategy (CreateStrategy .NOTHING );
142
145
}
143
- // Rebuild Target from Source.
144
- rtn = buildTableSchema (copySpec );
145
146
} else {
146
- let .addIssue ("Can't use COMMON for ACID tables" );
147
+ let .addIssue (SCHEMA_EXISTS_TARGET_MISMATCH . getDesc () );
147
148
ret .setCreateStrategy (CreateStrategy .NOTHING );
149
+ rtn = Boolean .TRUE ;
148
150
}
149
151
return rtn ;
150
152
}
0 commit comments