Skip to content
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

Added support for arrow output serialization #14431

Merged
merged 4 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sdk/storage/azure-storage-blob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Release History

## 12.9.0-beta.1 (Unreleased)

- Added support for the 2019-02-10 service version.
- Added support to specify Arrow Output Serialization when querying a blob.

## 12.8.0 (2020-08-13)
- Fixed a bug that, when the data length parameter did not match the actual length of the data in BlobClient.upload, caused a zero length blob to be uploaded rather than throwing an exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public AzureBlobStorageImpl build() {
if (this.version != null) {
client.setVersion(this.version);
} else {
client.setVersion("2019-12-12");
client.setVersion("2020-02-10");
}
if (this.pathRenameMode != null) {
client.setPathRenameMode(this.pathRenameMode);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.storage.blob.implementation.models;

import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import java.util.ArrayList;
import java.util.List;

/**
* arrow configuration.
*/
@JacksonXmlRootElement(localName = "ArrowConfiguration")
@Fluent
public final class ArrowConfiguration {
private static final class SchemaWrapper {
@JacksonXmlProperty(localName = "Field")
private final List<ArrowField> items;

@JsonCreator
private SchemaWrapper(@JacksonXmlProperty(localName = "Field") List<ArrowField> items) {
this.items = items;
}
}

/*
* The schema property.
*/
@JsonProperty(value = "Schema", required = true)
private SchemaWrapper schema;

/**
* Get the schema property: The schema property.
*
* @return the schema value.
*/
public List<ArrowField> getSchema() {
if (this.schema == null) {
this.schema = new SchemaWrapper(new ArrayList<ArrowField>());
}
return this.schema.items;
}

/**
* Set the schema property: The schema property.
*
* @param schema the schema value to set.
* @return the ArrowConfiguration object itself.
*/
public ArrowConfiguration setSchema(List<ArrowField> schema) {
this.schema = new SchemaWrapper(schema);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.storage.blob.implementation.models;

import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;

/**
* field of an arrow schema.
*/
@JacksonXmlRootElement(localName = "Field")
@Fluent
public final class ArrowField {
/*
* The type property.
*/
@JsonProperty(value = "Type", required = true)
private String type;

/*
* The name property.
*/
@JsonProperty(value = "Name")
private String name;

/*
* The precision property.
*/
@JsonProperty(value = "Precision")
private Integer precision;

/*
* The scale property.
*/
@JsonProperty(value = "Scale")
private Integer scale;

/**
* Get the type property: The type property.
*
* @return the type value.
*/
public String getType() {
return this.type;
}

/**
* Set the type property: The type property.
*
* @param type the type value to set.
* @return the ArrowField object itself.
*/
public ArrowField setType(String type) {
this.type = type;
return this;
}

/**
* Get the name property: The name property.
*
* @return the name value.
*/
public String getName() {
return this.name;
}

/**
* Set the name property: The name property.
*
* @param name the name value to set.
* @return the ArrowField object itself.
*/
public ArrowField setName(String name) {
this.name = name;
return this;
}

/**
* Get the precision property: The precision property.
*
* @return the precision value.
*/
public Integer getPrecision() {
return this.precision;
}

/**
* Set the precision property: The precision property.
*
* @param precision the precision value to set.
* @return the ArrowField object itself.
*/
public ArrowField setPrecision(Integer precision) {
this.precision = precision;
return this;
}

/**
* Get the scale property: The scale property.
*
* @return the scale value.
*/
public Integer getScale() {
return this.scale;
}

/**
* Set the scale property: The scale property.
*
* @param scale the scale value to set.
* @return the ArrowField object itself.
*/
public ArrowField setScale(Integer scale) {
this.scale = scale;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Fluent
public final class QueryFormat {
/*
* Possible values include: 'delimited', 'json'
* Possible values include: 'delimited', 'json', 'arrow'
*/
@JsonProperty(value = "Type")
private QueryFormatType type;
Expand All @@ -32,8 +32,15 @@ public final class QueryFormat {
@JsonProperty(value = "JsonTextConfiguration")
private JsonTextConfiguration jsonTextConfiguration;

/*
* The arrowConfiguration property.
*/
@JsonProperty(value = "ArrowConfiguration")
private ArrowConfiguration arrowConfiguration;

/**
* Get the type property: Possible values include: 'delimited', 'json'.
* Get the type property: Possible values include: 'delimited', 'json',
* 'arrow'.
*
* @return the type value.
*/
Expand All @@ -42,7 +49,8 @@ public QueryFormatType getType() {
}

/**
* Set the type property: Possible values include: 'delimited', 'json'.
* Set the type property: Possible values include: 'delimited', 'json',
* 'arrow'.
*
* @param type the type value to set.
* @return the QueryFormat object itself.
Expand Down Expand Up @@ -96,4 +104,24 @@ public QueryFormat setJsonTextConfiguration(JsonTextConfiguration jsonTextConfig
this.jsonTextConfiguration = jsonTextConfiguration;
return this;
}

/**
* Get the arrowConfiguration property: The arrowConfiguration property.
*
* @return the arrowConfiguration value.
*/
public ArrowConfiguration getArrowConfiguration() {
return this.arrowConfiguration;
}

/**
* Set the arrowConfiguration property: The arrowConfiguration property.
*
* @param arrowConfiguration the arrowConfiguration value to set.
* @return the QueryFormat object itself.
*/
public QueryFormat setArrowConfiguration(ArrowConfiguration arrowConfiguration) {
this.arrowConfiguration = arrowConfiguration;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ public enum QueryFormatType {
/**
* Enum value json.
*/
JSON("json");
JSON("json"),

/**
* Enum value arrow.
*/
ARROW("arrow");

/**
* The actual serialized value for a QueryFormatType instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
package com.azure.storage.blob.implementation.util;

import com.azure.core.util.logging.ClientLogger;
import com.azure.storage.blob.implementation.models.ArrowConfiguration;
import com.azure.storage.blob.implementation.models.ArrowField;
import com.azure.storage.blob.implementation.models.DelimitedTextConfiguration;
import com.azure.storage.blob.implementation.models.JsonTextConfiguration;
import com.azure.storage.blob.implementation.models.QueryFormat;
import com.azure.storage.blob.implementation.models.QueryFormatType;
import com.azure.storage.blob.implementation.models.QuerySerialization;
import com.azure.storage.blob.models.BlobQueryArrowField;
import com.azure.storage.blob.models.BlobQueryArrowSerialization;
import com.azure.storage.blob.models.BlobQueryDelimitedSerialization;
import com.azure.storage.blob.models.BlobQueryError;
import com.azure.storage.blob.models.BlobQueryJsonSerialization;
Expand All @@ -24,6 +28,7 @@

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
Expand Down Expand Up @@ -201,12 +206,12 @@ private static boolean checkParametersNotNull(Object... data) {
}

/**
* Transforms a generic BlobQuickQuerySerialization into a QuickQuerySerialization.
* Transforms a generic input BlobQuerySerialization into a QuerySerialization.
* @param userSerialization {@link BlobQuerySerialization}
* @param logger {@link ClientLogger}
* @return {@link QuerySerialization}
*/
public static QuerySerialization transformSerialization(BlobQuerySerialization userSerialization,
public static QuerySerialization transformInputSerialization(BlobQuerySerialization userSerialization,
ClientLogger logger) {
if (userSerialization == null) {
return null;
Expand All @@ -233,6 +238,46 @@ public static QuerySerialization transformSerialization(BlobQuerySerialization u
return new QuerySerialization().setFormat(generatedFormat);
}

/**
* Transforms a generic input BlobQuerySerialization into a QuerySerialization.
* @param userSerialization {@link BlobQuerySerialization}
* @param logger {@link ClientLogger}
* @return {@link QuerySerialization}
*/
public static QuerySerialization transformOutputSerialization(BlobQuerySerialization userSerialization,
ClientLogger logger) {
if (userSerialization == null) {
return null;
}

QueryFormat generatedFormat = new QueryFormat();
if (userSerialization instanceof BlobQueryDelimitedSerialization) {

generatedFormat.setType(QueryFormatType.DELIMITED);
generatedFormat.setDelimitedTextConfiguration(transformDelimited(
(BlobQueryDelimitedSerialization) userSerialization));

} else if (userSerialization instanceof BlobQueryJsonSerialization) {

generatedFormat.setType(QueryFormatType.JSON);
generatedFormat.setJsonTextConfiguration(transformJson(
(BlobQueryJsonSerialization) userSerialization));

} else if (userSerialization instanceof BlobQueryArrowSerialization) {

generatedFormat.setType(QueryFormatType.ARROW);
generatedFormat.setArrowConfiguration(transformArrow(
(BlobQueryArrowSerialization) userSerialization));

} else {
throw logger.logExceptionAsError(new IllegalArgumentException(
String.format("'output' must be one of %s, %s or %s", BlobQueryJsonSerialization.class.getSimpleName(),
BlobQueryDelimitedSerialization.class.getSimpleName(),
BlobQueryArrowSerialization.class.getSimpleName())));
}
return new QuerySerialization().setFormat(generatedFormat);
}

/**
* Transforms a BlobQuickQueryDelimitedSerialization into a DelimitedTextConfiguration.
*
Expand Down Expand Up @@ -266,6 +311,32 @@ private static JsonTextConfiguration transformJson(BlobQueryJsonSerialization js
.setRecordSeparator(charToString(jsonSerialization.getRecordSeparator()));
}

/**
* Transforms a BlobQueryArrowSerialization into a ArrowConfiguration.
*
* @param arrowSerialization {@link BlobQueryArrowSerialization}
* @return {@link ArrowConfiguration}
*/
private static ArrowConfiguration transformArrow(BlobQueryArrowSerialization arrowSerialization) {
if (arrowSerialization == null) {
return null;
}
List<ArrowField> schema = new ArrayList<>(arrowSerialization.getSchema().size());
for (BlobQueryArrowField field : arrowSerialization.getSchema()) {
if (field == null) {
schema.add(null);
} else {
schema.add(new ArrowField()
.setName(field.getName())
.setPrecision(field.getPrecision())
.setScale(field.getScale())
.setType(field.getType().toString())
);
}
}
return new ArrowConfiguration().setSchema(schema);
}

private static String charToString(char c) {
return c == '\0' ? "" : Character.toString(c);
}
Expand Down
Loading