Skip to content

Commit 04e02d9

Browse files
Implement commandType parameter for command history api (#119)
1 parent 2790cef commit 04e02d9

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/main/java/com/qubole/qds/sdk/java/api/CommandApi.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.qubole.qds.sdk.java.entities.Commands;
2121

2222
import javax.ws.rs.core.Response;
23+
import java.util.List;
2324

2425
/**
2526
* Corresponds to http://www.qubole.com/docs/documentation/command-api/
@@ -161,4 +162,7 @@ public interface CommandApi
161162
public CommandApi includeQueryProperties(boolean includeQueryProperties);
162163

163164
public CommandApi endDate(String endDate);
165+
166+
public CommandApi commandType(List<BaseCommand.COMMAND_TYPE> commandTypes);
167+
164168
}

src/main/java/com/qubole/qds/sdk/java/details/CommandApiImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626

2727
import javax.ws.rs.core.Response;
2828

29+
import java.util.List;
2930
import java.util.Map;
31+
import java.util.stream.Collectors;
32+
33+
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
34+
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
3035

3136
class CommandApiImpl implements CommandApi
3237
{
@@ -186,4 +191,15 @@ public CommandApi endDate(String endDate)
186191
return this;
187192
}
188193

194+
@Override
195+
public CommandApi commandType(List<BaseCommand.COMMAND_TYPE> commandTypes) {
196+
197+
String commandTypeCsv = commandTypes.stream()
198+
.filter(type -> type != BaseCommand.COMMAND_TYPE.NONE)
199+
.map(i -> UPPER_UNDERSCORE.to(UPPER_CAMEL, i + "_COMMAND"))
200+
.collect(Collectors.joining(","));
201+
202+
parameters.put("command_type", commandTypeCsv);
203+
return this;
204+
}
189205
}

src/test/java/com/qubole/qds/sdk/java/TestClient.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
*/
1616
package com.qubole.qds.sdk.java;
1717

18+
import com.google.common.collect.ImmutableList;
19+
import com.qubole.qds.sdk.java.api.BaseCommand;
1820
import com.qubole.qds.sdk.java.client.DefaultQdsConfiguration;
1921
import com.qubole.qds.sdk.java.client.QdsConfiguration;
2022
import com.qubole.qds.sdk.java.details.RequestDetails;
2123
import com.qubole.qds.sdk.java.details.ForPage;
2224
import com.qubole.qds.sdk.java.details.QdsClientImpl;
23-
import org.apache.http.client.utils.URIBuilder;
2425
import org.testng.Assert;
2526
import org.testng.annotations.Test;
2627
import javax.ws.rs.client.AsyncInvoker;
@@ -98,13 +99,21 @@ protected WebTarget prepareTarget(ForPage forPage, RequestDetails entity, String
9899
String endDate = "2018-07-13T23:59:59Z";
99100
boolean allUsers = false;
100101
boolean qProps = false;
101-
client.command().startDate(startDate).endDate(endDate).allUsers(allUsers).includeQueryProperties(qProps).history().invoke();
102+
103+
client.command()
104+
.startDate(startDate)
105+
.endDate(endDate)
106+
.allUsers(allUsers)
107+
.commandType(ImmutableList.of(BaseCommand.COMMAND_TYPE.HIVE, BaseCommand.COMMAND_TYPE.PRESTO))
108+
.includeQueryProperties(qProps).history().invoke();
109+
102110
WebTarget webTarget = webTargetReference.get();
103111
Assert.assertNotNull(webTarget);
104112
Assert.assertTrue(webTarget.getUri().toString().contains("end_date="+endDate.replaceAll(":", "%3A")));
105113
Assert.assertTrue(webTarget.getUri().toString().contains("include_query_properties="+qProps));
106114
Assert.assertTrue(webTarget.getUri().toString().contains("all_users="+0));
107115
Assert.assertTrue(webTarget.getUri().toString().contains("start_date="+startDate.replaceAll(":", "%3A")));
116+
Assert.assertTrue(webTarget.getUri().toString().contains("command_type=HiveCommand%2CPrestoCommand"));
108117
}
109118

110119

0 commit comments

Comments
 (0)