Skip to content

Commit

Permalink
Implement commandType parameter for command history api (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
VenkataKarthikP authored Jun 12, 2020
1 parent 2790cef commit 04e02d9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/qubole/qds/sdk/java/api/CommandApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.qubole.qds.sdk.java.entities.Commands;

import javax.ws.rs.core.Response;
import java.util.List;

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

public CommandApi endDate(String endDate);

public CommandApi commandType(List<BaseCommand.COMMAND_TYPE> commandTypes);

}
16 changes: 16 additions & 0 deletions src/main/java/com/qubole/qds/sdk/java/details/CommandApiImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@

import javax.ws.rs.core.Response;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.google.common.base.CaseFormat.UPPER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;

class CommandApiImpl implements CommandApi
{
Expand Down Expand Up @@ -186,4 +191,15 @@ public CommandApi endDate(String endDate)
return this;
}

@Override
public CommandApi commandType(List<BaseCommand.COMMAND_TYPE> commandTypes) {

String commandTypeCsv = commandTypes.stream()
.filter(type -> type != BaseCommand.COMMAND_TYPE.NONE)
.map(i -> UPPER_UNDERSCORE.to(UPPER_CAMEL, i + "_COMMAND"))
.collect(Collectors.joining(","));

parameters.put("command_type", commandTypeCsv);
return this;
}
}
13 changes: 11 additions & 2 deletions src/test/java/com/qubole/qds/sdk/java/TestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/
package com.qubole.qds.sdk.java;

import com.google.common.collect.ImmutableList;
import com.qubole.qds.sdk.java.api.BaseCommand;
import com.qubole.qds.sdk.java.client.DefaultQdsConfiguration;
import com.qubole.qds.sdk.java.client.QdsConfiguration;
import com.qubole.qds.sdk.java.details.RequestDetails;
import com.qubole.qds.sdk.java.details.ForPage;
import com.qubole.qds.sdk.java.details.QdsClientImpl;
import org.apache.http.client.utils.URIBuilder;
import org.testng.Assert;
import org.testng.annotations.Test;
import javax.ws.rs.client.AsyncInvoker;
Expand Down Expand Up @@ -98,13 +99,21 @@ protected WebTarget prepareTarget(ForPage forPage, RequestDetails entity, String
String endDate = "2018-07-13T23:59:59Z";
boolean allUsers = false;
boolean qProps = false;
client.command().startDate(startDate).endDate(endDate).allUsers(allUsers).includeQueryProperties(qProps).history().invoke();

client.command()
.startDate(startDate)
.endDate(endDate)
.allUsers(allUsers)
.commandType(ImmutableList.of(BaseCommand.COMMAND_TYPE.HIVE, BaseCommand.COMMAND_TYPE.PRESTO))
.includeQueryProperties(qProps).history().invoke();

WebTarget webTarget = webTargetReference.get();
Assert.assertNotNull(webTarget);
Assert.assertTrue(webTarget.getUri().toString().contains("end_date="+endDate.replaceAll(":", "%3A")));
Assert.assertTrue(webTarget.getUri().toString().contains("include_query_properties="+qProps));
Assert.assertTrue(webTarget.getUri().toString().contains("all_users="+0));
Assert.assertTrue(webTarget.getUri().toString().contains("start_date="+startDate.replaceAll(":", "%3A")));
Assert.assertTrue(webTarget.getUri().toString().contains("command_type=HiveCommand%2CPrestoCommand"));
}


Expand Down

0 comments on commit 04e02d9

Please sign in to comment.