MCPcopy Create free account
hub / github.com/apache/impala / load

Method load

fe/src/main/java/org/apache/impala/catalog/TableLoader.java:72–183  ·  view source on GitHub ↗

Creates the Impala representation of Hive/HBase metadata for one table. Calls load() on the appropriate instance of Table subclass. If the eventId is not negative, it fetches all events from metastore to find out a CREATE_TABLE event from metastore which is used to set the createEventId of the table

(Db db, String tblName, long eventId, String reason,
      EventSequence catalogTimeline)

Source from the content-addressed store, hash-verified

70 * an IncompleteTable will be returned that contains details on the error.
71 */
72 public Table load(Db db, String tblName, long eventId, String reason,
73 EventSequence catalogTimeline) {
74 Stopwatch sw = Stopwatch.createStarted();
75 String fullTblName = db.getName() + "." + tblName;
76 String annotation = "Loading metadata for: " + fullTblName + " (" + reason + ")";
77 LOG.info(annotation);
78 Table table = null;
79 boolean syncToLatestEventId =
80 BackendConfig.INSTANCE.enableSyncToLatestEventOnDdls();
81 // turn all exceptions into TableLoadingException
82 List<NotificationEvent> events = null;
83 try (ThreadNameAnnotator tna = new ThreadNameAnnotator(annotation);
84 MetaStoreClient msClient = catalog_.getMetaStoreClient(catalogTimeline)) {
85 org.apache.hadoop.hive.metastore.api.Table msTbl = null;
86 Stopwatch hmsLoadSW = Stopwatch.createStarted();
87 msTbl = msClient.getHiveClient().getTable(db.getName(), tblName);
88 catalogTimeline.markEvent(FETCHED_HMS_TABLE);
89 if (eventId != -1 && catalog_.isEventProcessingEnabled()) {
90 // If the eventId is not -1 it means this table was likely created by Impala.
91 // However, since the load operation of the table can happen much later, it is
92 // possible that the table was recreated outside Impala and hence the eventId
93 // which is stored in the loaded table needs to be updated to the latest.
94 // we are only interested in fetching the events if we have a valid eventId
95 // for a table. For tables where eventId is unknown are not created by
96 // this catalogd and hence the self-event detection logic does not apply.
97 events = MetastoreEventsProcessor.getNextMetastoreEventsInBatchesForTable(
98 catalog_, eventId, db.getName(), tblName, CreateTableEvent.EVENT_TYPE);
99 catalogTimeline.markEvent(FETCHED_HMS_EVENT_BATCH);
100 }
101 if (events != null && !events.isEmpty()) {
102 // if the table was recreated after the table was initially created in the
103 // catalogd, we should move the eventId forward to the latest create_table
104 // event.
105 eventId = events.get(events.size() - 1).getEventId();
106 }
107 long hmsLoadTime = hmsLoadSW.elapsed(TimeUnit.NANOSECONDS);
108 // Check that the Hive TableType is supported
109 TableType tableType = TableType.valueOf(msTbl.getTableType());
110 if (!MetastoreShim.IMPALA_SUPPORTED_TABLE_TYPES.contains(tableType)) {
111 throw new TableLoadingException(String.format(
112 "Unsupported table type '%s' for: %s", tableType, fullTblName));
113 }
114
115 // Support for Hive JDBC storage handler
116 String val = msTbl.getParameters().get("storage_handler");
117 if (val != null && val.equals("org.apache.hive.storage.jdbc.JdbcStorageHandler")) {
118 Map<String, String> impalaTblProps = setHiveJdbcProperties(msTbl);
119 msTbl.unsetParameters();
120 msTbl.setParameters(impalaTblProps);
121 }
122
123 // Create a table of appropriate type and have it load itself
124 table = Table.fromMetastoreTable(db, msTbl);
125 if (table == null) {
126 throw new TableLoadingException(
127 "Unrecognized table type for table: " + fullTblName);
128 }
129 table.updateHMSLoadTableSchemaTime(hmsLoadTime);

Callers

nothing calls this directly

Calls 15

elapsedMethod · 0.95
setHiveJdbcPropertiesMethod · 0.95
fromMetastoreTableMethod · 0.95
setCreateEventIdMethod · 0.95
getFullNameMethod · 0.95
loadMethod · 0.95
validateMethod · 0.95
setLastSyncedEventIdMethod · 0.95
syncToLatestEventIdMethod · 0.95
setLastRefreshEventIdMethod · 0.95

Tested by

no test coverage detected