Skip to content

Commit 94031b1

Browse files
authored
Merge pull request #151 from wujinhu/master
support select object operation
2 parents 196cf71 + 333dfe2 commit 94031b1

32 files changed

+1487
-122
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>com.aliyun.oss</groupId>
1313
<artifactId>aliyun-sdk-oss</artifactId>
14-
<version>3.1.0-SNAPSHOT</version>
14+
<version>3.3.0-SNAPSHOT</version>
1515
<packaging>jar</packaging>
1616
<name>Aliyun OSS SDK for Java</name>
1717
<description>The Aliyun OSS SDK for Java used for accessing Aliyun Object Storage Service</description>

src/main/java/com/aliyun/oss/ClientException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public String getRequestId() {
154154

155155
@Override
156156
public String getMessage() {
157-
return getErrorMessage() + "\n[ErrorCode]: " + errorCode != null ? errorCode
158-
: "" + "\n[RequestId]: " + requestId != null ? requestId : "";
157+
return getErrorMessage() + "\n[ErrorCode]: " + (errorCode != null ? errorCode
158+
: "") + "\n[RequestId]: " + (requestId != null ? requestId : "");
159159
}
160160
}

src/main/java/com/aliyun/oss/OSS.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* <p>
3737
* Object Store Service (a.k.a OSS) is the massive, secure, low cost and highly
3838
* reliable public storage which could be accessed from anywhere at anytime via
39-
* REST APIs, SDKs or web console. <br />
39+
* REST APIs, SDKs or web console. <br>
4040
* Developers could use OSS to create any services that need huge data storage
4141
* and access throughput, such as media sharing web apps, cloud storage service
4242
* or enterprise or personal data backup.
@@ -270,8 +270,8 @@ public interface OSS {
270270
* @param bucketName
271271
* Bucket name.
272272
* @param tags
273-
* The dictionary that contains the tags in the form of <key,
274-
* value> pairs
273+
* The dictionary that contains the tags in the form of &lt;key,
274+
* value&gt; pairs
275275
*/
276276
public void setBucketTagging(String bucketName, Map<String, String> tags) throws OSSException, ClientException;
277277

@@ -281,8 +281,8 @@ public interface OSS {
281281
* @param bucketName
282282
* Bucket name.
283283
* @param tagSet
284-
* {@link TagSet} instance that has the tags in the form of <key,
285-
* value> paris.
284+
* {@link TagSet} instance that has the tags in the form of &lt;key,
285+
* value&gt; paris.
286286
*/
287287
public void setBucketTagging(String bucketName, TagSet tagSet) throws OSSException, ClientException;
288288

@@ -612,6 +612,23 @@ public CopyObjectResult copyObject(String sourceBucketName, String sourceKey, St
612612
*/
613613
public OSSObject getObject(GetObjectRequest getObjectRequest) throws OSSException, ClientException;
614614

615+
/**
616+
* Select the {@link OSSObject} from the bucket specified in
617+
* {@link SelectObjectRequest} parameter
618+
* @param selectObjectRequest
619+
* A {@link SelectObjectRequest} instance which specifies the
620+
* bucket name
621+
* object key
622+
* filter expression
623+
* input serialization
624+
* output serialization
625+
* @return A {@link OSSObject} instance will be returned. The caller is
626+
* responsible to close the connection after usage.
627+
* @throws OSSException
628+
* @throws ClientException
629+
*/
630+
public OSSObject selectObject(SelectObjectRequest selectObjectRequest) throws OSSException, ClientException;
631+
615632
/**
616633
* Gets the {@link OSSObject} from the signed Url.
617634
*
@@ -679,6 +696,16 @@ public SimplifiedObjectMeta getSimplifiedObjectMeta(GenericRequest genericReques
679696
*/
680697
public ObjectMetadata getObjectMetadata(GenericRequest genericRequest) throws OSSException, ClientException;
681698

699+
/**
700+
* Create select object metadata(create metadata if not exists or overwrite flag set in {@link CreateSelectObjectMetadataRequest})
701+
*
702+
* @param createSelectObjectMetadataRequest
703+
* {@link CreateSelectObjectMetadataRequest} create select object metadata request.
704+
*
705+
* @return The {@link SelectObjectMetadata} instance.
706+
*/
707+
public SelectObjectMetadata createSelectObjectMetadata(CreateSelectObjectMetadataRequest createSelectObjectMetadataRequest) throws OSSException, ClientException;
708+
682709
/**
683710
* Append the data to the appendable object specified in
684711
* {@link AppendObjectRequest}. It's not applicable to normal OSS object.
@@ -1826,7 +1853,7 @@ public void setBucketStorageCapacity(SetBucketStorageCapacityRequest setBucketSt
18261853
*
18271854
* @param uploadFileRequest
18281855
* A {@link UploadFileRequest} instance that specifies the bucket
1829-
* name, object key, file path ,part size (>100K) and thread
1856+
* name, object key, file path ,part size (&gt; 100K) and thread
18301857
* count (from 1 to 1000) and checkpoint file.
18311858
* @return A {@link UploadFileRequest} instance which has the new uploaded
18321859
* file's key, ETag, location.
@@ -1848,7 +1875,7 @@ public void setBucketStorageCapacity(SetBucketStorageCapacityRequest setBucketSt
18481875
*
18491876
* @param downloadFileRequest
18501877
* A {@link DownloadFileRequest} instance that specifies the
1851-
* bucket name, object key, file path, part size (>100K) and
1878+
* bucket name, object key, file path, part size (&gt; 100K) and
18521879
* thread count (from 1 to 1000) and checkpoint file. Also it
18531880
* could have the ETag and ModifiedSince constraints.
18541881
* @return A {@link DownloadFileResult} instance that has the

src/main/java/com/aliyun/oss/OSSClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,11 @@ public OSSObject getObject(URL signedUrl, Map<String, String> requestHeaders) th
561561
return objectOperation.getObject(getObjectRequest);
562562
}
563563

564+
@Override
565+
public OSSObject selectObject(SelectObjectRequest selectObjectRequest) throws OSSException, ClientException {
566+
return objectOperation.selectObject(selectObjectRequest);
567+
}
568+
564569
@Override
565570
public SimplifiedObjectMeta getSimplifiedObjectMeta(String bucketName, String key)
566571
throws OSSException, ClientException {
@@ -578,6 +583,11 @@ public ObjectMetadata getObjectMetadata(String bucketName, String key) throws OS
578583
return this.getObjectMetadata(new GenericRequest(bucketName, key));
579584
}
580585

586+
@Override
587+
public SelectObjectMetadata createSelectObjectMetadata(CreateSelectObjectMetadataRequest createSelectObjectMetadataRequest) throws OSSException, ClientException {
588+
return objectOperation.createSelectObjectMetadata(createSelectObjectMetadataRequest);
589+
}
590+
581591
@Override
582592
public ObjectMetadata getObjectMetadata(GenericRequest genericRequest) throws OSSException, ClientException {
583593
return objectOperation.getObjectMetadata(genericRequest);

src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java

Lines changed: 86 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,15 @@
2929

3030
import com.aliyun.oss.ClientException;
3131
import com.aliyun.oss.common.comm.io.FixedLengthInputStream;
32+
import com.aliyun.oss.common.utils.BinaryUtil;
3233
import com.aliyun.oss.common.utils.DateUtil;
3334
import com.aliyun.oss.internal.RequestParameters;
35+
import com.aliyun.oss.model.*;
3436
import com.aliyun.oss.model.AddBucketReplicationRequest.ReplicationAction;
35-
import com.aliyun.oss.model.BucketReferer;
36-
import com.aliyun.oss.model.CompleteMultipartUploadRequest;
37-
import com.aliyun.oss.model.CreateBucketRequest;
38-
import com.aliyun.oss.model.CreateLiveChannelRequest;
39-
import com.aliyun.oss.model.CreateUdfApplicationRequest;
40-
import com.aliyun.oss.model.CreateUdfRequest;
41-
import com.aliyun.oss.model.DeleteBucketCnameRequest;
42-
import com.aliyun.oss.model.DeleteObjectsRequest;
43-
import com.aliyun.oss.model.ImageProcess;
44-
import com.aliyun.oss.model.LifecycleRule;
4537
import com.aliyun.oss.model.LifecycleRule.AbortMultipartUpload;
4638
import com.aliyun.oss.model.LifecycleRule.RuleStatus;
4739
import com.aliyun.oss.model.LifecycleRule.StorageTransition;
48-
import com.aliyun.oss.model.LiveChannelTarget;
49-
import com.aliyun.oss.model.PartETag;
50-
import com.aliyun.oss.model.ProcessObjectRequest;
51-
import com.aliyun.oss.model.PutBucketImageRequest;
52-
import com.aliyun.oss.model.PutImageStyleRequest;
53-
import com.aliyun.oss.model.ResizeUdfApplicationRequest;
54-
import com.aliyun.oss.model.SetBucketCORSRequest;
5540
import com.aliyun.oss.model.SetBucketCORSRequest.CORSRule;
56-
import com.aliyun.oss.model.DeleteBucketReplicationRequest;
57-
import com.aliyun.oss.model.RoutingRule;
58-
import com.aliyun.oss.model.AddBucketCnameRequest;
59-
import com.aliyun.oss.model.SetBucketLifecycleRequest;
60-
import com.aliyun.oss.model.SetBucketLoggingRequest;
61-
import com.aliyun.oss.model.AddBucketReplicationRequest;
62-
import com.aliyun.oss.model.SetBucketTaggingRequest;
63-
import com.aliyun.oss.model.SetBucketWebsiteRequest;
64-
import com.aliyun.oss.model.TagSet;
65-
import com.aliyun.oss.model.UdfApplicationConfiguration;
66-
import com.aliyun.oss.model.UpgradeUdfApplicationRequest;
67-
import com.aliyun.oss.model.UserQos;
6841

6942
/**
7043
* A collection of marshallers that marshall HTTP request into crossponding
@@ -99,6 +72,9 @@ public final class RequestMarshallers {
9972
public static final ResizeUdfApplicationRequestMarshaller resizeUdfApplicationRequestMarshaller = new ResizeUdfApplicationRequestMarshaller();
10073
public static final ProcessObjectRequestMarshaller processObjectRequestMarshaller = new ProcessObjectRequestMarshaller();
10174

75+
public static final CreateSelectObjectMetadataRequestMarshaller createSelectObjectMetadataRequestMarshaller = new CreateSelectObjectMetadataRequestMarshaller();
76+
public static final SelectObjectRequestMarshaller selectObjectRequestMarshaller = new SelectObjectRequestMarshaller();
77+
10278
public interface RequestMarshaller<R> extends Marshaller<FixedLengthInputStream, R> {
10379

10480
}
@@ -501,6 +477,87 @@ public FixedLengthInputStream marshall(CompleteMultipartUploadRequest request) {
501477

502478
}
503479

480+
public static final class CreateSelectObjectMetadataRequestMarshaller
481+
implements RequestMarshaller2<CreateSelectObjectMetadataRequest> {
482+
483+
@Override
484+
public byte[] marshall(CreateSelectObjectMetadataRequest request) {
485+
StringBuffer xmlBody = new StringBuffer();
486+
InputSerialization inputSerialization = request.getInputSerialization();
487+
CSVFormat csvFormat = inputSerialization.getCsvInputFormat();
488+
xmlBody.append("<CsvMetaRequest>");
489+
xmlBody.append("<InputSerialization>");
490+
xmlBody.append("<CompressionType>" + inputSerialization.getCompressionType() + "</CompressionType>");
491+
xmlBody.append("<CSV>");
492+
xmlBody.append("<RecordDelimiter>" + BinaryUtil.toBase64String(csvFormat.getRecordDelimiter().getBytes()) + "</RecordDelimiter>");
493+
xmlBody.append("<FieldDelimiter>" + BinaryUtil.toBase64String(csvFormat.getFieldDelimiter().toString().getBytes()) + "</FieldDelimiter>");
494+
xmlBody.append("<QuoteCharacter>" + BinaryUtil.toBase64String(csvFormat.getQuoteChar().toString().getBytes()) + "</QuoteCharacter>");
495+
xmlBody.append("</CSV>");
496+
xmlBody.append("</InputSerialization>");
497+
xmlBody.append("<OverwriteIfExists>" + request.isOverwrite() + "</OverwriteIfExists>");
498+
xmlBody.append("</CsvMetaRequest>");
499+
500+
try {
501+
return xmlBody.toString().getBytes(DEFAULT_CHARSET_NAME);
502+
} catch (UnsupportedEncodingException e) {
503+
throw new ClientException("Unsupported encoding " + e.getMessage(), e);
504+
}
505+
}
506+
}
507+
508+
public static final class SelectObjectRequestMarshaller implements RequestMarshaller2<SelectObjectRequest> {
509+
510+
@Override
511+
public byte[] marshall(SelectObjectRequest request) {
512+
StringBuffer xmlBody = new StringBuffer();
513+
xmlBody.append("<SelectRequest>");
514+
515+
xmlBody.append("<Expression>" + BinaryUtil.toBase64String(request.getExpression().getBytes()) + "</Expression>");
516+
xmlBody.append("<Options>");
517+
xmlBody.append("<SkipPartialDataRecord>" + request.isSkipPartialDataRecord() + "</SkipPartialDataRecord>");
518+
xmlBody.append("</Options>");
519+
InputSerialization inputSerialization = request.getInputSerialization();
520+
CSVFormat csvInputFormat = inputSerialization.getCsvInputFormat();
521+
xmlBody.append("<InputSerialization>");
522+
xmlBody.append("<CompressionType>" + inputSerialization.getCompressionType() + "</CompressionType>");
523+
xmlBody.append("<CSV>");
524+
xmlBody.append("<FileHeaderInfo>" + csvInputFormat.getHeaderInfo() + "</FileHeaderInfo>");
525+
xmlBody.append("<RecordDelimiter>" + BinaryUtil.toBase64String(csvInputFormat.getRecordDelimiter().getBytes()) + "</RecordDelimiter>");
526+
xmlBody.append("<FieldDelimiter>" + BinaryUtil.toBase64String(csvInputFormat.getFieldDelimiter().toString().getBytes()) + "</FieldDelimiter>");
527+
xmlBody.append("<QuoteCharacter>" + BinaryUtil.toBase64String(csvInputFormat.getQuoteChar().toString().getBytes()) + "</QuoteCharacter>");
528+
xmlBody.append("<CommentCharacter>" + BinaryUtil.toBase64String(csvInputFormat.getCommentChar().toString().getBytes()) + "</CommentCharacter>");
529+
530+
if (request.getLineRange() != null) {
531+
xmlBody.append("<Range>" + request.lineRangeToString(request.getLineRange()) + "</Range>");
532+
}
533+
if (request.getSplitRange() != null) {
534+
xmlBody.append("<Range>" + request.splitRangeToString(request.getSplitRange()) + "</Range>");
535+
}
536+
xmlBody.append("</CSV>");
537+
xmlBody.append("</InputSerialization>");
538+
OutputSerialization outputSerialization = request.getOutputSerialization();
539+
CSVFormat csvOutputFormat = outputSerialization.getCsvOutputFormat();
540+
xmlBody.append("<OutputSerialization>");
541+
xmlBody.append("<CSV>");
542+
xmlBody.append("<RecordDelimiter>" + BinaryUtil.toBase64String(csvOutputFormat.getRecordDelimiter().getBytes()) + "</RecordDelimiter>");
543+
xmlBody.append("<FieldDelimiter>" + BinaryUtil.toBase64String(csvOutputFormat.getFieldDelimiter().toString().getBytes()) + "</FieldDelimiter>");
544+
xmlBody.append("<QuoteCharacter>" + BinaryUtil.toBase64String(csvOutputFormat.getQuoteChar().toString().getBytes()) + "</QuoteCharacter>");
545+
xmlBody.append("</CSV>");
546+
xmlBody.append("<KeepAllColumns>" + outputSerialization.isKeepAllColumns() + "</KeepAllColumns>");
547+
xmlBody.append("<OutputRawData>" + outputSerialization.isOutputRawData() + "</OutputRawData>");
548+
xmlBody.append("<OutputHeader>" + outputSerialization.isOutputHeader() + "</OutputHeader>");
549+
xmlBody.append("<EnablePayloadCrc>" + outputSerialization.isPayloadCrcEnabled() + "</EnablePayloadCrc>");
550+
xmlBody.append("</OutputSerialization>");
551+
xmlBody.append("</SelectRequest>");
552+
553+
try {
554+
return xmlBody.toString().getBytes(DEFAULT_CHARSET_NAME);
555+
} catch (UnsupportedEncodingException e) {
556+
throw new ClientException("Unsupported encoding " + e.getMessage(), e);
557+
}
558+
}
559+
}
560+
504561
public static final class DeleteObjectsRequestMarshaller implements RequestMarshaller2<DeleteObjectsRequest> {
505562

506563
@Override

src/main/java/com/aliyun/oss/event/ProgressEventType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@ public enum ProgressEventType {
4444
/**
4545
* Transfer events.
4646
*/
47-
TRANSFER_PREPARING_EVENT, TRANSFER_STARTED_EVENT, TRANSFER_COMPLETED_EVENT, TRANSFER_FAILED_EVENT, TRANSFER_CANCELED_EVENT, TRANSFER_PART_STARTED_EVENT, TRANSFER_PART_COMPLETED_EVENT, TRANSFER_PART_FAILED_EVENT;
47+
TRANSFER_PREPARING_EVENT, TRANSFER_STARTED_EVENT, TRANSFER_COMPLETED_EVENT, TRANSFER_FAILED_EVENT, TRANSFER_CANCELED_EVENT, TRANSFER_PART_STARTED_EVENT, TRANSFER_PART_COMPLETED_EVENT, TRANSFER_PART_FAILED_EVENT,
48+
49+
/**
50+
* Select object events.
51+
*/
52+
SELECT_STARTED_EVENT, SELECT_SCAN_EVENT, SELECT_COMPLETED_EVENT, SELECT_FAILED_EVENT
4853
}

src/main/java/com/aliyun/oss/event/ProgressPublisher.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public static void publishProgress(final ProgressListener listener, final Progre
3333
listener.progressChanged(new ProgressEvent(eventType));
3434
}
3535

36+
public static void publishSelectProgress(final ProgressListener listener, final ProgressEventType eventType,
37+
final long scannedBytes) {
38+
if (listener == ProgressListener.NOOP || listener == null || eventType == null) {
39+
return;
40+
}
41+
listener.progressChanged(new ProgressEvent(eventType, scannedBytes));
42+
}
43+
3644
public static void publishRequestContentLength(final ProgressListener listener, final long bytes) {
3745
publishByteCountEvent(listener, REQUEST_CONTENT_LENGTH_EVENT, bytes);
3846
}

src/main/java/com/aliyun/oss/internal/OSSHeaders.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,12 @@ public interface OSSHeaders extends HttpHeaders {
8080
static final String OSS_ONGOING_RESTORE = "ongoing-request=\"true\"";
8181

8282
static final String OSS_BUCKET_REGION = "x-oss-bucket-region";
83+
84+
static final String OSS_SELECT_PREFIX = "x-oss-select";
85+
static final String OSS_SELECT_CSV_ROWS = OSS_SELECT_PREFIX + "-csv-rows";
86+
static final String OSS_SELECT_OUTPUT_RAW = OSS_SELECT_PREFIX + "-output-raw";
87+
static final String OSS_SELECT_CSV_SPLITS = OSS_SELECT_PREFIX + "-csv-splits";
88+
static final String OSS_SELECT_INPUT_LINE_RANGE = OSS_SELECT_PREFIX + "-line-range";
89+
static final String OSS_SELECT_INPUT_SPLIT_RANGE = OSS_SELECT_PREFIX + "-split-range";
90+
8391
}

0 commit comments

Comments
 (0)