-
Notifications
You must be signed in to change notification settings - Fork 703
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
[CARBONDATA-4263]support query with latestSegment #4189
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,13 +18,7 @@ | |
package org.apache.carbondata.hadoop.api; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.*; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.stream.Collectors; | ||
|
||
|
@@ -222,7 +216,9 @@ public List<InputSplit> getSplits(JobContext job) throws IOException { | |
*/ | ||
private List<Segment> getFilteredSegment(JobContext job, List<Segment> validSegments, | ||
boolean validationRequired, ReadCommittedScope readCommittedScope) throws IOException { | ||
Segment[] segmentsToAccess = getSegmentsToAccess(job, readCommittedScope); | ||
// first check for mapreduce.input.carboninputformat.segmentnumbers | ||
// second check for table property of latest_segment for query | ||
Segment[] segmentsToAccess = getSegmentsToAccess(job, readCommittedScope, validSegments); | ||
if (segmentsToAccess.length == 0 || segmentsToAccess[0].getSegmentNo().equalsIgnoreCase("*")) { | ||
return validSegments; | ||
} | ||
|
@@ -421,9 +417,11 @@ public void updateLoadMetaDataDetailsToSegments(List<Segment> validSegments, | |
|
||
/** | ||
* return valid segment to access | ||
* check for SET carbon.input.segments.<database_name>.<table_name> | ||
*/ | ||
public Segment[] getSegmentsToAccess(JobContext job, ReadCommittedScope readCommittedScope) { | ||
String segmentString = job.getConfiguration().get(INPUT_SEGMENT_NUMBERS, ""); | ||
|
||
if (segmentString.trim().isEmpty()) { | ||
return new Segment[0]; | ||
} | ||
|
@@ -601,4 +599,60 @@ public String getSegmentIdFromFilePath(String filePath) { | |
} | ||
return CarbonCommonConstants.INVALID_SEGMENT_ID; | ||
} | ||
|
||
/** | ||
* return valid segment to access | ||
* first check for mapreduce.input.carboninputformat.segmentnumbers" | ||
* second check for table property of latest_segment for query | ||
*/ | ||
public Segment[] getSegmentsToAccess(JobContext job, ReadCommittedScope readCommittedScope, | ||
List<Segment> validSegments) { | ||
String segmentString = job.getConfiguration().get(INPUT_SEGMENT_NUMBERS, ""); | ||
boolean queryLatestSegment = false; | ||
if (null != carbonTable) { | ||
queryLatestSegment = Boolean.parseBoolean(carbonTable.getTableInfo() | ||
.getFactTable().getTableProperties() | ||
.getOrDefault(CarbonCommonConstants.TABLE_QUERY_LATEST_SEGMENT, "false")); | ||
} | ||
if (segmentString.trim().isEmpty()) { | ||
if (!queryLatestSegment) { | ||
return new Segment[0]; | ||
} else { | ||
List<Segment> segments = getLatestSegment(validSegments); | ||
return segments.toArray(new Segment[0]); | ||
} | ||
} else { | ||
List<Segment> segments = Segment.toSegmentList(segmentString.split(","), readCommittedScope); | ||
if (!queryLatestSegment) { | ||
return segments.toArray(new Segment[0]); | ||
} else { | ||
List<Segment> latestSegment; | ||
if (segments.size() > 0 && segments.get(0).getSegmentNo().equalsIgnoreCase("*")) { | ||
latestSegment = getLatestSegment(validSegments); | ||
} else { | ||
latestSegment = getLatestSegment(segments); | ||
} | ||
return latestSegment.toArray(new Segment[0]); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* get the latest segment | ||
* @param validSegments the in put segment for search | ||
* @return the latest segment for query | ||
*/ | ||
public List<Segment> getLatestSegment(List<Segment> validSegments) { | ||
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. if we need a single segment, then why return type is List? 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. In order to be consistent with the external interfaces, in addition, if the latest segments are required, they also have consistency |
||
if (validSegments.isEmpty()) { | ||
return Collections.emptyList(); | ||
} else { | ||
Segment segment = validSegments.stream().max((a, b) -> { | ||
double aNo = Double.parseDouble(a.getSegmentNo()); | ||
double bNo = Double.parseDouble(b.getSegmentNo()); | ||
return Double.compare(aNo, bNo); | ||
}).get(); | ||
return Collections.singletonList(segment); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
shortField,intField,bigintField,doubleField,stringField,timestampField,decimalField,dateField,charField,floatField,complexData | ||
1,10,1100,48.4,,,1.23,2015/4/23,aaa,2.5,'foo'#'bar'#'world' | ||
5,17,1140,43.4,,2015/7/27 12:01:02,3.45,2015/7/27,bbb,2.5,'foo'#'bar'#'world' | ||
1,11,1100,44.4,,2015/5/23 12:01:03,23.23,2015/5/23,ccc,2.5,'foo'#'bar'#'world' | ||
1,10,1150,43.4,spark,,254.12,2015/7/24,ddd,2.5,'foo'#'bar'#'world' | ||
1,10,1100,47.4,spark,2015/7/23 12:01:05,876.14,2015/7/23,eeee,3.5,'foo'#'bar'#'world' | ||
3,14,1160,43.4,hive,2015/7/26 12:01:06,3454.32,2015/7/26,ff,2.5,'foo'#'bar'#'world' | ||
2,,,43.4,impala,2015/7/23 12:01:07,456.98,2015/7/23,ggg,2.5,'foo'#'bar'#'world' | ||
,10,1100,43.4,spark,,32.53,2015/5/23,hhh,2.5,'foo'#'bar'#'world' | ||
4,16,1130,42.4,impala,2015/7/23 12:01:09,67.23,2015/7/23,iii,2.5, | ||
1,10,1100,43.4,spark,2015/7/23 12:01:10,832.23,2015/7/23,jjj,,'foo'#'bar'#'world' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
shortField,intField,bigintField,doubleField,stringField,timestampField,decimalField,dateField,charField,floatField,complexData | ||
1,10,1100,48.4,spark,2015/4/23 12:01:01,1.23,2015/4/23,aaa,2.5,'foo'#'bar'#'world' | ||
5,17,1140,43.4,spark,2015/7/27 12:01:02,3.45,2015/7/27,bbb,2.5,'foo'#'bar'#'world' | ||
1,11,1100,44.4,flink,2015/5/23 12:01:03,23.23,2015/5/23,ccc,2.5,'foo'#'bar'#'world' | ||
1,10,1150,43.4,spark,2015/7/24 12:01:04,254.12,2015/7/24,ddd,2.5,'foo'#'bar'#'world' | ||
1,10,1100,47.4,spark,2015/7/23 12:01:05,876.14,2015/7/23,eeee,3.5,'foo'#'bar'#'world' | ||
3,14,1160,43.4,hive,2015/7/26 12:01:06,3454.32,2015/7/26,ff,2.5,'foo'#'bar'#'world' | ||
2,10,1100,43.4,impala,2015/7/23 12:01:07,456.98,2015/7/23,ggg,2.5,'foo'#'bar'#'world' | ||
1,10,1100,43.4,spark,2015/5/23 12:01:08,32.53,2015/5/23,hhh,2.5,'foo'#'bar'#'world' | ||
4,16,1130,42.4,impala,2015/7/23 12:01:09,67.23,2015/7/23,iii,2.5,'foo'#'bar'#'world' | ||
1,10,1100,43.4,spark,2015/7/23 12:01:10,832.23,2015/7/23,jjj,2.5,'foo'#'bar'#'world' |
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.
call getSegmentsToAccess(JobContext job, ReadCommittedScope readCommittedScope) to get the segments set in configuration, instead of writing the code again
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.
the old getSegmentsToAccess fun just use INPUT_SEGMENT_NUMBERS for input to get the segment List.
But now we need get segment not just INPUT_SEGMENT_NUMBERS but alse latest segment. the validSegments is need to use.
if use getSegmentsToAccess(JobContext job, ReadCommittedScope readCommittedScope) we need to analysis readCommittedScope to validSegments that the external functions have been implemented.
so i choose func overload to do this function.