Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 0 additions & 28 deletions src/main/java/com/treasuredata/client/TDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import com.treasuredata.client.model.TDJobRequest;
import com.treasuredata.client.model.TDJobSubmitResult;
import com.treasuredata.client.model.TDJobSummary;
import com.treasuredata.client.model.TDPartialDeleteJob;
import com.treasuredata.client.model.TDResultFormat;
import com.treasuredata.client.model.TDSaveQueryRequest;
import com.treasuredata.client.model.TDSavedQuery;
Expand Down Expand Up @@ -564,33 +563,6 @@ public void deleteTableIfExists(String databaseName, String tableName)
}
}

@Override
public TDPartialDeleteJob partialDelete(String databaseName, String tableName, long from, long to)
throws TDClientException
{
return partialDelete(databaseName, tableName, from, to, null);
}

@Override
public TDPartialDeleteJob partialDelete(String databaseName, String tableName, long from, long to, String domainKey)
throws TDClientException
{
if ((from % 3600 != 0) || (to % 3600 != 0)) {
throw new TDClientException(TDClientException.ErrorType.INVALID_INPUT, String.format("from/to value must be a multiple of 3600: [%s, %s)", from, to));
}

Map<String, String> queryParams = new HashMap<>();
queryParams.put("from", Long.toString(from));
queryParams.put("to", Long.toString(to));

if (domainKey != null) {
queryParams.put("domain_key", domainKey);
}

TDPartialDeleteJob job = doPost(buildUrl("/v3/table/partialdelete", databaseName, tableName), Collections.unmodifiableMap(queryParams), TDPartialDeleteJob.class);
return job;
}

@Override
public void swapTables(String databaseName, String tableName1, String tableName2)
{
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/treasuredata/client/TDClientApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.treasuredata.client.model.TDJobList;
import com.treasuredata.client.model.TDJobRequest;
import com.treasuredata.client.model.TDJobSummary;
import com.treasuredata.client.model.TDPartialDeleteJob;
import com.treasuredata.client.model.TDResultFormat;
import com.treasuredata.client.model.TDSaveQueryRequest;
import com.treasuredata.client.model.TDSavedQuery;
Expand Down Expand Up @@ -215,10 +214,6 @@ public interface TDClientApi<ClientImpl>

void deleteTableIfExists(String databaseName, String tableName);

TDPartialDeleteJob partialDelete(String databaseName, String tableName, long from, long to);

TDPartialDeleteJob partialDelete(String databaseName, String tableName, long from, long to, String domainKey);

void swapTables(String databaseName, String tableName1, String tableName2);

// schema API
Expand Down

This file was deleted.

94 changes: 14 additions & 80 deletions src/test/java/com/treasuredata/client/TestTDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import com.treasuredata.client.model.TDJobRequest;
import com.treasuredata.client.model.TDJobRequestBuilder;
import com.treasuredata.client.model.TDJobSummary;
import com.treasuredata.client.model.TDPartialDeleteJob;
import com.treasuredata.client.model.TDResultFormat;
import com.treasuredata.client.model.TDSaveQueryRequest;
import com.treasuredata.client.model.TDSavedQuery;
Expand Down Expand Up @@ -1001,85 +1000,6 @@ private static String newTemporaryName(String prefix)
return prefix + "_" + dateStr;
}

@Test
public void partialDeleteTest()
throws Exception
{
String t = newTemporaryName("td_client_test");
try {
client.deleteTableIfExists(SAMPLE_DB, t);

String jobId = client.submit(TDJobRequest.newPrestoQuery(SAMPLE_DB,
String.format("CREATE TABLE %s AS SELECT * FROM (VALUES TD_TIME_PARSE('2015-01-01', 'UTC'), TD_TIME_PARSE('2015-02-01', 'UTC')) as sample(time)", t, t)));

waitJobCompletion(jobId);

String before = queryResult(SAMPLE_DB, String.format("SELECT * FROM %s", t));

assertTrue(before.contains("1420070400"));
assertTrue(before.contains("1422748800"));

// delete 2015-01-01 entry
try {
client.partialDelete(SAMPLE_DB, t, 1420070400, 1420070400 + 1);
fail("should not reach here");
}
catch (TDClientException e) {
assertEquals(TDClientException.ErrorType.INVALID_INPUT, e.getErrorType());
}
long from = 1420070400 - (1420070400 % 3600);
long to = from + 3600;
TDPartialDeleteJob partialDeleteJob = client.partialDelete(SAMPLE_DB, t, from, to);
logger.debug("partial delete job: " + partialDeleteJob);
assertEquals(from, partialDeleteJob.getFrom());
assertEquals(to, partialDeleteJob.getTo());
assertEquals(SAMPLE_DB, partialDeleteJob.getDatabase());
assertEquals(t, partialDeleteJob.getTable());

waitJobCompletion(partialDeleteJob.getJobId());

String after = queryResult(SAMPLE_DB, String.format("SELECT * FROM %s", t));
assertFalse(after.contains("1420070400"));
assertTrue(after.contains("1422748800"));
}
finally {
client.deleteTableIfExists(SAMPLE_DB, t);
}
}

@Test
public void partialDeleteWithDomainKeyTest()
throws Exception
{
String domainKey = randomDomainKey();

String t = newTemporaryName("td_client_test");
try {
client.deleteTableIfExists(SAMPLE_DB, t);

String jobId = client.submit(TDJobRequest.newPrestoQuery(SAMPLE_DB,
String.format("CREATE TABLE %s AS SELECT * FROM (VALUES TD_TIME_PARSE('2015-01-01', 'UTC'), TD_TIME_PARSE('2015-02-01', 'UTC')) as sample(time)", t, t)));

waitJobCompletion(jobId);

int from = 1420070400;
int to = from + 3600;

TDPartialDeleteJob deleteJob = client.partialDelete(SAMPLE_DB, t, from, to, domainKey);

try {
client.partialDelete(SAMPLE_DB, t, from, to, domainKey);
fail("Expected " + TDClientHttpConflictException.class.getName());
}
catch (TDClientHttpConflictException e) {
assertThat(e.getConflictsWith(), is(Optional.of(deleteJob.getJobId())));
}
}
finally {
client.deleteTableIfExists(SAMPLE_DB, t);
}
}

@Test
public void swapTest()
throws Exception
Expand Down Expand Up @@ -1248,9 +1168,23 @@ public void testBulkImport()
}

// Check the data
// It seems it needs some time to reflect the data in TD,
// so we will wait for few mins before checking the data
deadline = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5);

TDTable imported = client.listTables(SAMPLE_DB).stream().filter(input -> {
return input.getName().equals(bulkImportTable);
}).findFirst().get();
while (imported.getRowCount() == 0) {
if (System.currentTimeMillis() > deadline) {
throw new IllegalStateException("timeout error: data is not imported yet");
}
logger.info("Waiting data import step completion");
Thread.sleep(TimeUnit.SECONDS.toMillis(5));
imported = client.listTables(SAMPLE_DB).stream().filter(input -> {
return input.getName().equals(bulkImportTable);
}).findFirst().get();
}

assertEquals(numRowsInPart * 2, imported.getRowCount());
List<TDColumn> columns = imported.getColumns();
Expand Down
Loading