Skip to content

Commit

Permalink
data type collections (Azure#346)
Browse files Browse the repository at this point in the history
* Remove static DataType collections and use Collection static methods instead
* Modify AutoRest readme
  • Loading branch information
rabee333 authored Dec 17, 2019
1 parent 1870391 commit cb4dc62
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,44 +55,14 @@ public final class DataType extends ExpandableStringEnum<DataType> {
public static final DataType EDM_COMPLEX_TYPE = fromString("Edm.ComplexType");

/**
* Static value Collection(Edm.String) for DataType.
* Returns a collection of a specific DataType
* @param dataType the corresponding DataType
* @return a Collection of the corresponding DataType
*/
public static final DataType COLLECTION_EDM_STRING = fromString("Collection(Edm.String)");

/**
* Static value Collection(Edm.Int32) for DataType.
*/
public static final DataType COLLECTION_EDM_INT32 = fromString("Collection(Edm.Int32)");

/**
* Static value Collection(Edm.Int64) for DataType.
*/
public static final DataType COLLECTION_EDM_INT64 = fromString("Collection(Edm.Int64)");

/**
* Static value Collection(Edm.Double) for DataType.
*/
public static final DataType COLLECTION_EDM_DOUBLE = fromString("Collection(Edm.Double)");

/**
* Static value Collection(Edm.Boolean) for DataType.
*/
public static final DataType COLLECTION_EDM_BOOLEAN = fromString("Collection(Edm.Boolean)");

/**
* Static value Collection(Edm.DateTimeOffset) for DataType.
*/
public static final DataType COLLECTION_EDM_DATE_TIME_OFFSET = fromString("Collection(Edm.DateTimeOffset)");

/**
* Static value Collection(Edm.GeographyPoint) for DataType.
*/
public static final DataType COLLECTION_EDM_GEOGRAPHY_POINT = fromString("Collection(Edm.GeographyPoint)");

/**
* Static value Collection(Edm.ComplexType) for DataType.
*/
public static final DataType COLLECTION_EDM_COMPLEX_TYPE = fromString("Collection(Edm.ComplexType)");
@JsonCreator
public static DataType Collection(DataType dataType) {
return fromString(String.format("Collection(%s)", dataType.toString()));
}

/**
* Creates or finds a DataType from its string representation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void main(String[] args) {
getServiceStatistics(client);
}

static void getServiceStatistics(SearchServiceClient client) {
private static void getServiceStatistics(SearchServiceClient client) {
ServiceStatistics serviceStatistics = client.getServiceStatistics();

System.out.println(":" + serviceStatistics);
Expand All @@ -62,45 +62,45 @@ static void getServiceStatistics(SearchServiceClient client) {
e.printStackTrace();
}

/** Output:
* {
* "counters":{
* "documentCount":{
* "usage":5009,
* "quota":null
* },
* "indexesCount":{
* "usage":4,
* "quota":50
* },
* "indexersCount":{
* "usage":2,
* "quota":50
* },
* "dataSourcesCount":{
* "usage":2,
* "quota":50
* },
* "storageSize":{
* "usage":19551042,
* "quota":26843545600
* },
* "synonymMaps":{
* "usage":0,
* "quota":5
* }
* },
* "limits":{
* "maxFieldsPerIndex":1000,
* "maxFieldNestingDepthPerIndex":10,
* "maxComplexCollectionFieldsPerIndex":40,
* "maxComplexObjectsInCollectionsPerDocument":3000
* }
* }
/* Output:
{
"counters":{
"documentCount":{
"usage":5009,
"quota":null
},
"indexesCount":{
"usage":4,
"quota":50
},
"indexersCount":{
"usage":2,
"quota":50
},
"dataSourcesCount":{
"usage":2,
"quota":50
},
"storageSize":{
"usage":19551042,
"quota":26843545600
},
"synonymMaps":{
"usage":0,
"quota":5
}
},
"limits":{
"maxFieldsPerIndex":1000,
"maxFieldNestingDepthPerIndex":10,
"maxComplexCollectionFieldsPerIndex":40,
"maxComplexObjectsInCollectionsPerDocument":3000
}
}
*/
}

static void getIndexStatistics(SearchServiceClient client) {
private static void getIndexStatistics(SearchServiceClient client) {
Index testIndex = createTestIndex();
Index index = client.createOrUpdateIndex(testIndex);
IndexGetStatisticsResult result = client.getIndexStatistics(index.getName());
Expand All @@ -120,8 +120,8 @@ static void getIndexStatistics(SearchServiceClient client) {
*
* @return an Index
*/
static Index createTestIndex() {
Map<String, Double> weights = new HashMap<String, Double>();
private static Index createTestIndex() {
Map<String, Double> weights = new HashMap<>();
weights.put("Description", 1.5);
weights.put("Category", 2.0);
return new Index()
Expand Down Expand Up @@ -183,7 +183,7 @@ static Index createTestIndex() {
.setRetrievable(Boolean.TRUE),
new Field()
.setName("Tags")
.setType(DataType.COLLECTION_EDM_STRING)
.setType(DataType.Collection(DataType.EDM_STRING))
.setSearchable(Boolean.TRUE)
.setFilterable(Boolean.TRUE)
.setSortable(Boolean.FALSE)
Expand Down Expand Up @@ -270,7 +270,7 @@ static Index createTestIndex() {
.setRetrievable(Boolean.TRUE),
new Field()
.setName("Rooms")
.setType(DataType.COLLECTION_EDM_COMPLEX_TYPE)
.setType(DataType.Collection(DataType.EDM_COMPLEX_TYPE))
.setFields(Arrays.asList(
new Field()
.setName("Description")
Expand Down Expand Up @@ -320,7 +320,7 @@ static Index createTestIndex() {
.setRetrievable(Boolean.TRUE),
new Field()
.setName("Tags")
.setType(DataType.COLLECTION_EDM_STRING)
.setType(DataType.Collection(DataType.EDM_STRING))
.setSearchable(Boolean.TRUE)
.setFilterable(Boolean.TRUE)
.setSortable(Boolean.FALSE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private static Index createIndex(SearchServiceClient client) {
.setAnalyzer("en.microsoft"),
new Field()
.setName("Tags")
.setType(DataType.COLLECTION_EDM_STRING)
.setType(DataType.Collection(DataType.EDM_STRING))
.setFacetable(Boolean.TRUE)
.setFilterable(Boolean.TRUE)
.setRetrievable(Boolean.TRUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void canUseAllAnalyzerNamesInIndexDefinition() {

// All analyzer names can be set on the analyzer property.
for (int i = 0; i < allAnalyzerNames.size(); i++) {
DataType fieldType = (i % 2 == 0) ? DataType.EDM_STRING : DataType.COLLECTION_EDM_STRING;
DataType fieldType = (i % 2 == 0) ? DataType.EDM_STRING : DataType.Collection(DataType.EDM_STRING);
fields.add(new Field()
.setName("field" + (fieldNumber++))
.setType(fieldType)
Expand All @@ -163,7 +163,7 @@ public void canUseAllAnalyzerNamesInIndexDefinition() {
List<AnalyzerName> searchAnalyzersAndIndexAnalyzers = getAnalyzersAllowedForSearchAnalyzerAndIndexAnalyzer();

for (int i = 0; i < searchAnalyzersAndIndexAnalyzers.size(); i++) {
DataType fieldType = (i % 2 == 0) ? DataType.EDM_STRING : DataType.COLLECTION_EDM_STRING;
DataType fieldType = (i % 2 == 0) ? DataType.EDM_STRING : DataType.Collection(DataType.EDM_STRING);
fields.add(new Field()
.setName("field" + (fieldNumber++))
.setType(fieldType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void canUseAllAnalyzerNamesInIndexDefinition() {

// All analyzer names can be set on the analyzer property.
for (int i = 0; i < allAnalyzerNames.size(); i++) {
DataType fieldType = (i % 2 == 0) ? DataType.EDM_STRING : DataType.COLLECTION_EDM_STRING;
DataType fieldType = (i % 2 == 0) ? DataType.EDM_STRING : DataType.Collection(DataType.EDM_STRING);
fields.add(new Field()
.setName("field" + (fieldNumber++))
.setType(fieldType)
Expand All @@ -163,7 +163,7 @@ public void canUseAllAnalyzerNamesInIndexDefinition() {
List<AnalyzerName> searchAnalyzersAndIndexAnalyzers = getAnalyzersAllowedForSearchAnalyzerAndIndexAnalyzer();

for (int i = 0; i < searchAnalyzersAndIndexAnalyzers.size(); i++) {
DataType fieldType = (i % 2 == 0) ? DataType.EDM_STRING : DataType.COLLECTION_EDM_STRING;
DataType fieldType = (i % 2 == 0) ? DataType.EDM_STRING : DataType.Collection(DataType.EDM_STRING);
fields.add(new Field()
.setName("field" + (fieldNumber++))
.setType(fieldType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ public abstract class SearchServiceTestBase extends TestBase {

private JsonApi jsonApi = JsonWrapper.newInstance(JacksonDeserializer.class);

@Override
public String getTestName() {
return testName.getMethodName();
}

@Rule
public TestName testName = new TestName();

Expand Down Expand Up @@ -149,8 +144,8 @@ protected SearchServiceClientBuilder getSearchServiceClientBuilder() {
* @param policies the additional HTTP pipeline policies
* @return {@link SearchServiceClientBuilder}
*/
protected SearchServiceClientBuilder getSearchServiceClientBuilderWithHttpPipelinePolicies(
List<HttpPipelinePolicy> policies) {
SearchServiceClientBuilder getSearchServiceClientBuilderWithHttpPipelinePolicies(
List<HttpPipelinePolicy> policies) {
SearchServiceClientBuilder builder = new SearchServiceClientBuilder()
.endpoint(endpoint);

Expand Down Expand Up @@ -241,7 +236,7 @@ Index createTestIndex() {
.setRetrievable(Boolean.TRUE),
new Field()
.setName("Tags")
.setType(DataType.COLLECTION_EDM_STRING)
.setType(DataType.Collection(DataType.EDM_STRING))
.setSearchable(Boolean.TRUE)
.setFilterable(Boolean.TRUE)
.setSortable(Boolean.FALSE)
Expand Down Expand Up @@ -328,7 +323,7 @@ Index createTestIndex() {
.setRetrievable(Boolean.TRUE),
new Field()
.setName("Rooms")
.setType(DataType.COLLECTION_EDM_COMPLEX_TYPE)
.setType(DataType.Collection(DataType.EDM_COMPLEX_TYPE))
.setFields(Arrays.asList(
new Field()
.setName("Description")
Expand Down Expand Up @@ -378,7 +373,7 @@ Index createTestIndex() {
.setRetrievable(Boolean.TRUE),
new Field()
.setName("Tags")
.setType(DataType.COLLECTION_EDM_STRING)
.setType(DataType.Collection(DataType.EDM_STRING))
.setSearchable(Boolean.TRUE)
.setFilterable(Boolean.TRUE)
.setSortable(Boolean.FALSE)
Expand Down
21 changes: 6 additions & 15 deletions sdk/search/open-api/service-readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,12 @@ directive:
from: "search-request-options"
to: "request-options"

# Add missing data types to DataType
- from: swagger-document
where: $.definitions.DataType.enum
transform: |
if (!$.includes("Collection(Edm.String)")) {
$.push("Collection(Edm.String)",
"Collection(Edm.Int32)",
"Collection(Edm.Int64)",
"Collection(Edm.Double)",
"Collection(Edm.Boolean)",
"Collection(Edm.DateTimeOffset)",
"Collection(Edm.GeographyPoint)",
"Collection(Edm.ComplexType)"
);
}
# Add static Collection<DataType> method to DataType
- from: DataType.java
where: $
transform: >-
return $
.replace(/(public static final DataType EDM_COMPLEX_TYPE = fromString\("Edm.ComplexType"\);)/g, "$1\n\n /**\n * Returns a collection of a specific DataType\n * @param dataType the corresponding DataType\n * @return a Collection of the corresponding DataType\n */\n @JsonCreator\n public static DataType Collection(DataType dataType) {\n return fromString(String.format(\"Collection(%s)\", dataType.toString()));\n }")
# Workaround to fix bad host path parameters
- from:
Expand Down

0 comments on commit cb4dc62

Please sign in to comment.