@@ -48,68 +48,8 @@ public class TranslatorService {
48
48
49
49
@ Getter
50
50
private ExecuteSessionService executeSessionService = null ;
51
- // @Getter
52
- // private ConfigService configService = null;
53
-
54
- // private ConfigService configService;
55
51
private DatabaseService databaseService ;
56
52
57
- // @Autowired
58
- // public void setConfigService(ConfigService configService) {
59
- // this.configService = configService;
60
- // }
61
-
62
- /**
63
- * @param consolidationLevel how far up the directory hierarchy to go to build the distcp list based on the sources
64
- * provided.
65
- * @return A map of databases. Each database will have a map that has 1 or more 'targets' and 'x' sources for each
66
- * target.
67
- */
68
- // public synchronized Map<String, Map<String, Set<String>>> buildDistcpList(String database, Environment environment, int consolidationLevel) {
69
- // Map<String, Map<String, Set<String>>> rtn = new TreeMap<>();
70
- //
71
- // HmsMirrorConfig hmsMirrorConfig = executeSessionService.getSession().getConfig();
72
- //
73
- // // get the map for a db.
74
- // Set<String> databases = hmsMirrorConfig.getTranslator().getTranslationMap().keySet();
75
- //
76
- // // get the map.entry
77
- // Map<String, Set<String>> reverseMap = new TreeMap<>();
78
- // // Get a static view of set to avoid concurrent modification.
79
- // Set<EnvironmentMap.TranslationLevel> dbTranslationLevel =
80
- // new HashSet<>(hmsMirrorConfig.getTranslator().getTranslationMap(database, environment));
81
- //
82
- // Map<String, String> dbLocationMap = new TreeMap<>();
83
- //
84
- // for (EnvironmentMap.TranslationLevel translationLevel : dbTranslationLevel) {
85
- // if (translationLevel.getOriginal() != null &&
86
- // translationLevel.getTarget() != null) {
87
- // dbLocationMap.put(translationLevel.getAdjustedOriginal(), translationLevel.getAdjustedTarget());
88
- // }
89
- // }
90
- //
91
- // for (Map.Entry<String, String> entry : dbLocationMap.entrySet()) {
92
- // // reduce folder level by 'consolidationLevel' for key and value.
93
- // // Source
94
- // String reducedSource = UrlUtils.reduceUrlBy(entry.getKey(), consolidationLevel);
95
- // // Target
96
- // String reducedTarget = UrlUtils.reduceUrlBy(entry.getValue(), consolidationLevel);
97
- //
98
- // if (reverseMap.get(reducedTarget) != null) {
99
- // reverseMap.get(reducedTarget).add(entry.getKey());
100
- // } else {
101
- // Set<String> sourceSet = new TreeSet<String>();
102
- // sourceSet.add(entry.getKey());
103
- // reverseMap.put(reducedTarget, sourceSet);
104
- // }
105
- //
106
- // }
107
- // if (!reverseMap.isEmpty()) {
108
- // rtn.put(database, reverseMap);
109
- // }
110
- // return rtn;
111
- // }
112
-
113
53
public String buildPartitionAddStatement (EnvironmentTable environmentTable ) {
114
54
StringBuilder sbPartitionDetails = new StringBuilder ();
115
55
Map <String , String > partitions = new HashMap <String , String >();
@@ -187,7 +127,10 @@ public Boolean translatePartitionLocations(TableMirror tblMirror) throws Require
187
127
for (Map .Entry <String , String > entry : partitionLocationMap .entrySet ()) {
188
128
String partitionLocation = entry .getValue ();
189
129
String partSpec = entry .getKey ();
190
- int level = StringUtils .countMatches (partSpec , "/" ) + 1 ;
130
+ // First level partitions are +2 from the DB level. So we need to add 2 to the level.
131
+ // EG: The spec for a single partition will have level 1.
132
+ String spec [] = partSpec .split ("/" );
133
+ int level = spec .length + 1 ;
191
134
// Increase level to the table, since we're not filter any tables. It's assumed that
192
135
// we're pulling the whole DB.
193
136
// if (!config.getFilter().isTableFiltering()) {
@@ -258,8 +201,6 @@ public String translateLocation(TableMirror tableMirror, String originalLocation
258
201
259
202
if (config .getDataStrategy () == DataStrategyEnum .STORAGE_MIGRATION
260
203
&& origNamespace .equals (config .getTransfer ().getTargetNamespace ())) {
261
- // tableMirror.addIssue(Environment.LEFT, "Location Mapping can't be determined. No matching `glm` entry to make translation." +
262
- // "Original Location: " + originalLocation);
263
204
tableMirror .setPhaseState (PhaseState .ERROR );
264
205
throw new MissingDataPointException ("Location Mapping can't be determined. No matching `glm` entry to make translation." +
265
206
"Original Location: " + originalLocation );
@@ -381,8 +322,6 @@ public Map<String, Map<TableType, String>> getGlobalLocationMap() {
381
322
}
382
323
383
324
public Map <String , Map <TableType , String >> buildGlobalLocationMapFromWarehousePlansAndSources (boolean dryrun , int consolidationLevel ) throws MismatchException , SessionException {
384
- // Don't reload if running.
385
- // executeSessionService.clearActiveSession();
386
325
387
326
HmsMirrorConfig config = executeSessionService .getSession ().getConfig ();
388
327
@@ -427,7 +366,6 @@ public Map<String, Map<TableType, String>> buildGlobalLocationMapFromWarehousePl
427
366
*/
428
367
429
368
for (Map .Entry <String , Warehouse > warehouseEntry : warehousePlans .entrySet ()) {
430
- // String database = warehouseEntry.getKey();
431
369
String database = HmsMirrorConfigUtil .getResolvedDB (warehouseEntry .getKey (), config );
432
370
Warehouse warehouse = warehouseEntry .getValue ();
433
371
String externalBaseLocation = warehouse .getExternalDirectory ();
@@ -438,32 +376,12 @@ public Map<String, Map<TableType, String>> buildGlobalLocationMapFromWarehousePl
438
376
String typeTargetLocation = null ;
439
377
String extTargetLocation = new String (externalBaseLocation + "/" + database + ".db" );
440
378
String mngdTargetLocation = new String (managedBaseLocation + "/" + database + ".db" );
441
- // Set the location based on the table type.
442
-
443
- // switch (sourceLocationEntry.getKey()) {
444
- // case EXTERNAL_TABLE:
445
- // typeTargetLocation = externalBaseLocation;
446
- // break;
447
- // case MANAGED_TABLE:
448
- // typeTargetLocation = managedBaseLocation;
449
- // break;
450
- // }
451
- // typeTargetLocation = typeTargetLocation + "/" + database + ".db";
379
+
452
380
// Locations and the tables that are in that location.
453
381
for (Map .Entry <String , Set <String >> sourceLocationSet : sourceLocationEntry .getValue ().entrySet ()) {
454
382
String sourceLocation = new String (sourceLocationSet .getKey ());
455
383
// Strip the namespace from the location.
456
384
sourceLocation = NamespaceUtils .stripNamespace (sourceLocation ); //.replace(hmsMirrorConfig.getCluster(Environment.LEFT).getHcfsNamespace(), "");
457
- // I don't think this is relevant anymore, since we switch the namespace stripping to not required the LEFT hcfsNamespace.
458
- // if (config.getTransfer().getStorageMigration().isStrict() && (!sourceLocation.startsWith("/") || (sourceLocation.length() == sourceLocationSet.getKey().length()))) {
459
- // // Issue with reducing the location.
460
- // // This happens when the table(s) location doesn't match the source namespace.
461
- // throw new MismatchException("Location doesn't start with the configured namespace. This is a problem"
462
- // + " and doesn't allow for the location to be converted to the new namespace."
463
- // + " Location: " + sourceLocationSet.getKey() + " Database: " + database + " Type: " + sourceLocationEntry.getKey()
464
- // + " containing tables: " + String.join(",", sourceLocationSet.getValue())
465
- // + " HCFS Namespace: " + config.getCluster(Environment.LEFT).getHcfsNamespace());
466
- // }
467
385
468
386
// NOTE: The locations were already reduced by '1' when the Sources were built.
469
387
// This removed the 'table' directory from the location and allows for them to
0 commit comments