-
Notifications
You must be signed in to change notification settings - Fork 985
DRILL-5429: Improve query performance for MapR DB JSON Tables #817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,7 +58,9 @@ public class JsonTableGroupScan extends MapRDBGroupScan { | |
|
|
||
| public static final String TABLE_JSON = "json"; | ||
|
|
||
| private MapRDBTableStats tableStats; | ||
| private long totalRowCount; | ||
| private Table table; | ||
| private TabletInfo[] tabletInfos; | ||
|
|
||
| private JsonScanSpec scanSpec; | ||
|
|
||
|
|
@@ -90,7 +92,12 @@ private JsonTableGroupScan(JsonTableGroupScan that) { | |
| super(that); | ||
| this.scanSpec = that.scanSpec; | ||
| this.endpointFragmentMapping = that.endpointFragmentMapping; | ||
| this.tableStats = that.tableStats; | ||
|
|
||
| // Reusing the table handle, tabletInfos and totalRowCount saves expensive | ||
| // calls to MapR DB client to get them again. | ||
| this.table = that.table; | ||
| this.tabletInfos = that.tabletInfos; | ||
| this.totalRowCount = that.totalRowCount; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -100,30 +107,57 @@ public GroupScan clone(List<SchemaPath> columns) { | |
| return newScan; | ||
| } | ||
|
|
||
| /** | ||
| * Create a new groupScan, which is a clone of this. | ||
| * Initialize scanSpec. | ||
| * We should recompute regionsToScan as it depends upon scanSpec. | ||
| * @param scanSpec | ||
| */ | ||
| public JsonTableGroupScan clone(JsonScanSpec scanSpec) { | ||
| JsonTableGroupScan newScan = new JsonTableGroupScan(this); | ||
| newScan.scanSpec = scanSpec; | ||
| newScan.computeRegionsToScan(); | ||
| return newScan; | ||
| } | ||
|
|
||
| /** | ||
| * Compute regions to scan based on the scanSpec | ||
| */ | ||
| private void computeRegionsToScan() { | ||
| boolean foundStartRegion = false; | ||
|
|
||
| regionsToScan = new TreeMap<TabletFragmentInfo, String>(); | ||
| for (TabletInfo tabletInfo : tabletInfos) { | ||
| TabletInfoImpl tabletInfoImpl = (TabletInfoImpl) tabletInfo; | ||
| if (!foundStartRegion && !isNullOrEmpty(scanSpec.getStartRow()) && !tabletInfoImpl.containsRow(scanSpec.getStartRow())) { | ||
| continue; | ||
| } | ||
| foundStartRegion = true; | ||
| regionsToScan.put(new TabletFragmentInfo(tabletInfoImpl), tabletInfo.getLocations()[0]); | ||
| if (!isNullOrEmpty(scanSpec.getStopRow()) && tabletInfoImpl.containsRow(scanSpec.getStopRow())) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void init() { | ||
| logger.debug("Getting tablet locations"); | ||
| try { | ||
| Configuration conf = new Configuration(); | ||
| Table t = MapRDB.getTable(scanSpec.getTableName()); | ||
| TabletInfo[] tabletInfos = t.getTabletInfos(scanSpec.getCondition()); | ||
| tableStats = new MapRDBTableStats(conf, scanSpec.getTableName()); | ||
|
|
||
| boolean foundStartRegion = false; | ||
| regionsToScan = new TreeMap<TabletFragmentInfo, String>(); | ||
| // Fetch table and tabletInfo only once and cache. | ||
| table = MapRDB.getTable(scanSpec.getTableName()); | ||
| tabletInfos = table.getTabletInfos(scanSpec.getCondition()); | ||
|
|
||
| // Calculate totalRowCount for the table from tabletInfos estimatedRowCount. | ||
| // This will avoid calling expensive MapRDBTableStats API to get total rowCount, avoiding | ||
| // duplicate work and RPCs to MapR DB server. | ||
| for (TabletInfo tabletInfo : tabletInfos) { | ||
| TabletInfoImpl tabletInfoImpl = (TabletInfoImpl) tabletInfo; | ||
| if (!foundStartRegion | ||
| && !isNullOrEmpty(scanSpec.getStartRow()) | ||
| && !tabletInfoImpl.containsRow(scanSpec.getStartRow())) { | ||
| continue; | ||
| } | ||
| foundStartRegion = true; | ||
| regionsToScan.put(new TabletFragmentInfo(tabletInfoImpl), tabletInfo.getLocations()[0]); | ||
| if (!isNullOrEmpty(scanSpec.getStopRow()) | ||
| && tabletInfoImpl.containsRow(scanSpec.getStopRow())) { | ||
| break; | ||
| } | ||
| totalRowCount += tabletInfo.getEstimatedNumRows(); | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add your explanation as a comment
|
||
| computeRegionsToScan(); | ||
|
|
||
| } catch (Exception e) { | ||
| throw new DrillRuntimeException("Error getting region info for table: " + scanSpec.getTableName(), e); | ||
| } | ||
|
|
@@ -153,7 +187,7 @@ public MapRDBSubScan getSpecificScan(int minorFragmentId) { | |
| @Override | ||
| public ScanStats getScanStats() { | ||
| //TODO: look at stats for this. | ||
| long rowCount = (long) ((scanSpec.getSerializedFilter() != null ? .5 : 1) * tableStats.getNumRows()); | ||
| long rowCount = (long) ((scanSpec.getSerializedFilter() != null ? .5 : 1) * totalRowCount); | ||
| int avgColumnSize = 10; | ||
| int numColumns = (columns == null || columns.isEmpty()) ? 100 : columns.size(); | ||
| return new ScanStats(GroupScanProperty.NO_EXACT_ROW_COUNT, rowCount, 1, avgColumnSize * numColumns * rowCount); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comments describing the function