org.apache.flink.table.client.gateway.TypedResult Java Examples

The following examples show how to use org.apache.flink.table.client.gateway.TypedResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalExecutorITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private List<String> retrieveTableResult(
		Executor executor,
		SessionContext session,
		String resultID) throws InterruptedException {

	final List<String> actualResults = new ArrayList<>();
	while (true) {
		Thread.sleep(50); // slow the processing down
		final TypedResult<Integer> result = executor.snapshotResult(session, resultID, 2);
		if (result.getType() == TypedResult.ResultType.PAYLOAD) {
			actualResults.clear();
			IntStream.rangeClosed(1, result.getPayload()).forEach((page) -> {
				for (Row row : executor.retrieveResultPage(resultID, page)) {
					actualResults.add(row.toString());
				}
			});
		} else if (result.getType() == TypedResult.ResultType.EOS) {
			break;
		}
	}

	return actualResults;
}
 
Example #2
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private List<String> retrieveChangelogResult(
		Executor executor,
		SessionContext session,
		String resultID) throws InterruptedException {

	final List<String> actualResults = new ArrayList<>();
	while (true) {
		Thread.sleep(50); // slow the processing down
		final TypedResult<List<Tuple2<Boolean, Row>>> result =
				executor.retrieveResultChanges(session, resultID);
		if (result.getType() == TypedResult.ResultType.PAYLOAD) {
			for (Tuple2<Boolean, Row> change : result.getPayload()) {
				actualResults.add(change.toString());
			}
		} else if (result.getType() == TypedResult.ResultType.EOS) {
			break;
		}
	}
	return actualResults;
}
 
Example #3
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private List<String> retrieveTableResult(
		Executor executor,
		SessionContext session,
		String resultID) throws InterruptedException {

	final List<String> actualResults = new ArrayList<>();
	while (true) {
		Thread.sleep(50); // slow the processing down
		final TypedResult<Integer> result = executor.snapshotResult(session, resultID, 2);
		if (result.getType() == TypedResult.ResultType.PAYLOAD) {
			actualResults.clear();
			IntStream.rangeClosed(1, result.getPayload()).forEach((page) -> {
				for (Row row : executor.retrieveResultPage(resultID, page)) {
					actualResults.add(row.toString());
				}
			});
		} else if (result.getType() == TypedResult.ResultType.EOS) {
			break;
		}
	}

	return actualResults;
}
 
Example #4
Source File: MaterializedCollectBatchResult.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypedResult<Integer> snapshot(int pageSize) {
	synchronized (resultLock) {
		// the job finished with an exception
		SqlExecutionException e = executionException.get();
		if (e != null) {
			throw e;
		}

		// wait for a result
		if (null == resultTable) {
			return TypedResult.empty();
		}
		// we return a payload result the first time and EoS for the rest of times as if the results
		// are retrieved dynamically
		else if (!snapshotted) {
			snapshotted = true;
			this.pageSize = pageSize;
			pageCount = Math.max(1, (int) Math.ceil(((double) resultTable.size() / pageSize)));
			return TypedResult.payload(pageCount);
		} else {
			return TypedResult.endOfStream();
		}
	}
}
 
Example #5
Source File: MaterializedCollectBatchResult.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public TypedResult<Integer> snapshot(int pageSize) {
	synchronized (resultLock) {
		// wait for a result
		if (retrievalThread.isAlive() && null == resultTable) {
			return TypedResult.empty();
		}
		// the job finished with an exception
		else if (executionException != null) {
			throw executionException;
		}
		// we return a payload result the first time and EoS for the rest of times as if the results
		// are retrieved dynamically
		else if (!snapshotted) {
			snapshotted = true;
			this.pageSize = pageSize;
			pageCount = Math.max(1, (int) Math.ceil(((double) resultTable.size() / pageSize)));
			return TypedResult.payload(pageCount);
		} else {
			return TypedResult.endOfStream();
		}
	}
}
 
Example #6
Source File: TestingExecutor.java    From flink with Apache License 2.0 6 votes vote down vote up
TestingExecutor(
		List<SupplierWithException<TypedResult<List<Tuple2<Boolean, Row>>>, SqlExecutionException>> resultChanges,
		List<SupplierWithException<TypedResult<Integer>, SqlExecutionException>> snapshotResults,
		List<SupplierWithException<List<Row>, SqlExecutionException>> resultPages,
		BiConsumerWithException<String, String, SqlExecutionException> useCatalogConsumer,
		BiConsumerWithException<String, String, SqlExecutionException> useDatabaseConsumer,
		BiFunctionWithException<String, String, TableResult, SqlExecutionException> executeSqlConsumer,
		TriFunctionWithException<String, String, String, Void, SqlExecutionException> setSessionPropertyFunction,
		FunctionWithException<String, Void, SqlExecutionException> resetSessionPropertiesFunction) {
	this.resultChanges = resultChanges;
	this.snapshotResults = snapshotResults;
	this.resultPages = resultPages;
	this.useCatalogConsumer = useCatalogConsumer;
	this.useDatabaseConsumer = useDatabaseConsumer;
	this.executeSqlConsumer = executeSqlConsumer;
	this.setSessionPropertyFunction = setSessionPropertyFunction;
	this.resetSessionPropertiesFunction = resetSessionPropertiesFunction;
	helper = new SqlParserHelper();
	helper.registerTables();
}
 
Example #7
Source File: CliTableauResultViewTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyStreamingResult() {
	ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, true);

	TestingExecutor mockExecutor = new TestingExecutorBuilder()
		.setResultChangesSupplier(TypedResult::endOfStream)
		.build();

	CliTableauResultView view = new CliTableauResultView(
			terminal, mockExecutor, "session", resultDescriptor);

	view.displayStreamResults();
	view.close();

	Assert.assertEquals(
			"+-----+---------+-------------+----------------------+----------------------+----------------+----------------------------+" + System.lineSeparator() +
			"| +/- | boolean |         int |               bigint |              varchar | decimal(10, 5) |                  timestamp |" + System.lineSeparator() +
			"+-----+---------+-------------+----------------------+----------------------+----------------+----------------------------+" + System.lineSeparator() +
			"Received a total of 0 rows" + System.lineSeparator(),
			terminalOutput.toString());
	assertThat(mockExecutor.getNumCancelCalls(), is(0));
}
 
Example #8
Source File: LocalExecutorITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private List<String> retrieveChangelogResult(
		Executor executor,
		SessionContext session,
		String resultID) throws InterruptedException {

	final List<String> actualResults = new ArrayList<>();
	while (true) {
		Thread.sleep(50); // slow the processing down
		final TypedResult<List<Tuple2<Boolean, Row>>> result =
				executor.retrieveResultChanges(session, resultID);
		if (result.getType() == TypedResult.ResultType.PAYLOAD) {
			for (Tuple2<Boolean, Row> change : result.getPayload()) {
				actualResults.add(change.toString());
			}
		} else if (result.getType() == TypedResult.ResultType.EOS) {
			break;
		}
	}
	return actualResults;
}
 
Example #9
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private List<String> retrieveTableResult(
		Executor executor,
		String sessionId,
		String resultID) throws InterruptedException {

	final List<String> actualResults = new ArrayList<>();
	while (true) {
		Thread.sleep(50); // slow the processing down
		final TypedResult<Integer> result = executor.snapshotResult(sessionId, resultID, 2);
		if (result.getType() == TypedResult.ResultType.PAYLOAD) {
			actualResults.clear();
			IntStream.rangeClosed(1, result.getPayload()).forEach((page) -> {
				for (Row row : executor.retrieveResultPage(resultID, page)) {
					actualResults.add(row.toString());
				}
			});
		} else if (result.getType() == TypedResult.ResultType.EOS) {
			break;
		}
	}

	return actualResults;
}
 
Example #10
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private List<String> retrieveChangelogResult(
		Executor executor,
		String sessionId,
		String resultID) throws InterruptedException {

	final List<String> actualResults = new ArrayList<>();
	while (true) {
		Thread.sleep(50); // slow the processing down
		final TypedResult<List<Tuple2<Boolean, Row>>> result =
			executor.retrieveResultChanges(sessionId, resultID);
		if (result.getType() == TypedResult.ResultType.PAYLOAD) {
			for (Tuple2<Boolean, Row> change : result.getPayload()) {
				actualResults.add(change.toString());
			}
		} else if (result.getType() == TypedResult.ResultType.EOS) {
			break;
		}
	}
	return actualResults;
}
 
Example #11
Source File: MaterializedCollectBatchResult.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public TypedResult<Integer> snapshot(int pageSize) {
	synchronized (resultLock) {
		// wait for a result
		if (retrievalThread.isAlive() && null == resultTable) {
			return TypedResult.empty();
		}
		// the job finished with an exception
		else if (executionException != null) {
			throw executionException;
		}
		// we return a payload result the first time and EoS for the rest of times as if the results
		// are retrieved dynamically
		else if (!snapshotted) {
			snapshotted = true;
			this.pageSize = pageSize;
			pageCount = Math.max(1, (int) Math.ceil(((double) resultTable.size() / pageSize)));
			return TypedResult.payload(pageCount);
		} else {
			return TypedResult.endOfStream();
		}
	}
}
 
Example #12
Source File: CliTableauResultViewTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyBatchResult() {
	ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, true);
	TestingExecutor mockExecutor = new TestingExecutorBuilder()
		.setSnapshotResultSupplier(
			() -> TypedResult.payload(1),
			TypedResult::endOfStream
		)
		.setResultPageSupplier(Collections::emptyList)
		.build();

	CliTableauResultView view = new CliTableauResultView(
			terminal, mockExecutor, "session", resultDescriptor);

	view.displayBatchResults();
	view.close();

	Assert.assertEquals(
			"+---------+-----+--------+---------+----------------+-----------+" + System.lineSeparator() +
			"| boolean | int | bigint | varchar | decimal(10, 5) | timestamp |" + System.lineSeparator() +
			"+---------+-----+--------+---------+----------------+-----------+" + System.lineSeparator() +
			"0 row in set" + System.lineSeparator(),
			terminalOutput.toString());
	assertThat(mockExecutor.getNumCancelCalls(), is(0));
}
 
Example #13
Source File: LocalExecutor.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypedResult<Integer> snapshotResult(SessionContext session, String resultId, int pageSize) throws SqlExecutionException {
	final DynamicResult<?> result = resultStore.getResult(resultId);
	if (result == null) {
		throw new SqlExecutionException("Could not find a result with result identifier '" + resultId + "'.");
	}
	if (!result.isMaterialized()) {
		throw new SqlExecutionException("Invalid result retrieval mode.");
	}
	return ((MaterializedResult<?>) result).snapshot(pageSize);
}
 
Example #14
Source File: CliTableResultView.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected void refresh() {
	// take snapshot
	TypedResult<Integer> result;
	try {
		result = client.getExecutor().snapshotResult(client.getContext(), resultDescriptor.getResultId(), getVisibleMainHeight());
	} catch (SqlExecutionException e) {
		close(e);
		return;
	}

	// stop retrieval if job is done
	if (result.getType() == TypedResult.ResultType.EOS) {
		stopRetrieval(false);
	}
	// update page
	else if (result.getType() == TypedResult.ResultType.PAYLOAD) {
		int newPageCount = result.getPayload();
		pageCount = newPageCount;
		if (page > newPageCount) {
			page = LAST_PAGE;
		}
		updatePage();
	}

	lastRetrieval = LocalTime.now();

	// reset view
	resetAllParts();
}
 
Example #15
Source File: CollectStreamResult.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
protected <T> TypedResult<T> handleMissingResult() {
	// check if the monitoring thread is still there
	// we need to wait until we know what is going on
	if (monitoringThread.isAlive()) {
		return TypedResult.empty();
	}
	// the job finished with an exception
	else if (executionException != null) {
		throw executionException;
	}
	// we assume that a bounded job finished
	else {
		return TypedResult.endOfStream();
	}
}
 
Example #16
Source File: CliResultViewTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void testResultViewClearResult(TypedResult<?> typedResult, boolean isTableMode, int expectedCancellationCount) throws Exception {
	final CountDownLatch cancellationCounterLatch = new CountDownLatch(expectedCancellationCount);
	final SessionContext session = new SessionContext("test-session", new Environment());
	final MockExecutor executor = new MockExecutor(typedResult, cancellationCounterLatch);
	final ResultDescriptor descriptor = new ResultDescriptor(
		"result-id",
		TableSchema.builder().field("Null Field", Types.STRING()).build(),
		false);

	Thread resultViewRunner = null;
	CliClient cli = null;
	try {
		cli = new CliClient(TerminalUtils.createDummyTerminal(), session, executor);
		resultViewRunner = new Thread(new TestingCliResultView(cli, descriptor, isTableMode));
		resultViewRunner.start();
	} finally {
		if (resultViewRunner != null && !resultViewRunner.isInterrupted()) {
			resultViewRunner.interrupt();
		}
		if (cli != null) {
			cli.close();
		}
	}

	assertTrue(
		"Invalid number of cancellations.",
		cancellationCounterLatch.await(10, TimeUnit.SECONDS));
}
 
Example #17
Source File: CollectStreamResult.java    From flink with Apache License 2.0 5 votes vote down vote up
protected <T> TypedResult<T> handleMissingResult() {
	// check if the monitoring thread is still there
	// we need to wait until we know what is going on
	if (monitoringThread.isAlive()) {
		return TypedResult.empty();
	}
	// the job finished with an exception
	else if (executionException != null) {
		throw executionException;
	}
	// we assume that a bounded job finished
	else {
		return TypedResult.endOfStream();
	}
}
 
Example #18
Source File: CliTableResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected void refresh() {
	// take snapshot
	TypedResult<Integer> result;
	try {
		result = client.getExecutor().snapshotResult(client.getContext(), resultDescriptor.getResultId(), getVisibleMainHeight());
	} catch (SqlExecutionException e) {
		close(e);
		return;
	}

	// stop retrieval if job is done
	if (result.getType() == TypedResult.ResultType.EOS) {
		stopRetrieval(false);
	}
	// update page
	else if (result.getType() == TypedResult.ResultType.PAYLOAD) {
		int newPageCount = result.getPayload();
		pageCount = newPageCount;
		if (page > newPageCount) {
			page = LAST_PAGE;
		}
		updatePage();
	}

	lastRetrieval = LocalTime.now();

	// reset view
	resetAllParts();
}
 
Example #19
Source File: LocalExecutor.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public TypedResult<Integer> snapshotResult(SessionContext session, String resultId, int pageSize) throws SqlExecutionException {
	final DynamicResult<?> result = resultStore.getResult(resultId);
	if (result == null) {
		throw new SqlExecutionException("Could not find a result with result identifier '" + resultId + "'.");
	}
	if (!result.isMaterialized()) {
		throw new SqlExecutionException("Invalid result retrieval mode.");
	}
	return ((MaterializedResult<?>) result).snapshot(pageSize);
}
 
Example #20
Source File: CliResultViewTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void testResultViewClearResult(TypedResult<?> typedResult, boolean isTableMode, int expectedCancellationCount) throws Exception {
	final CountDownLatch cancellationCounterLatch = new CountDownLatch(expectedCancellationCount);
	final SessionContext session = new SessionContext("test-session", new Environment());
	final MockExecutor executor = new MockExecutor(typedResult, cancellationCounterLatch);
	final ResultDescriptor descriptor = new ResultDescriptor(
		"result-id",
		TableSchema.builder().field("Null Field", Types.STRING()).build(),
		false);

	Thread resultViewRunner = null;
	CliClient cli = null;
	try {
		cli = new CliClient(TerminalUtils.createDummyTerminal(), session, executor);
		resultViewRunner = new Thread(new TestingCliResultView(cli, descriptor, isTableMode));
		resultViewRunner.start();
	} finally {
		if (resultViewRunner != null && !resultViewRunner.isInterrupted()) {
			resultViewRunner.interrupt();
		}
		if (cli != null) {
			cli.close();
		}
	}

	assertTrue(
		"Invalid number of cancellations.",
		cancellationCounterLatch.await(10, TimeUnit.SECONDS));
}
 
Example #21
Source File: LocalExecutor.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypedResult<List<Tuple2<Boolean, Row>>> retrieveResultChanges(
		String sessionId,
		String resultId) throws SqlExecutionException {
	final DynamicResult<?> result = resultStore.getResult(resultId);
	if (result == null) {
		throw new SqlExecutionException("Could not find a result with result identifier '" + resultId + "'.");
	}
	if (result.isMaterialized()) {
		throw new SqlExecutionException("Invalid result retrieval mode.");
	}
	return ((ChangelogResult<?>) result).retrieveChanges();
}
 
Example #22
Source File: LocalExecutor.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypedResult<Integer> snapshotResult(String sessionId, String resultId, int pageSize) throws SqlExecutionException {
	final DynamicResult<?> result = resultStore.getResult(resultId);
	if (result == null) {
		throw new SqlExecutionException("Could not find a result with result identifier '" + resultId + "'.");
	}
	if (!result.isMaterialized()) {
		throw new SqlExecutionException("Invalid result retrieval mode.");
	}
	return ((MaterializedResult<?>) result).snapshot(pageSize);
}
 
Example #23
Source File: MaterializedCollectStreamResult.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypedResult<Integer> snapshot(int pageSize) {
	if (pageSize < 1) {
		throw new SqlExecutionException("Page size must be greater than 0.");
	}

	synchronized (resultLock) {
		// retrieval thread is dead and there are no results anymore
		// or program failed
		if ((!isRetrieving() && isLastSnapshot) || executionException.get() != null) {
			return handleMissingResult();
		}
		// this snapshot is the last result that can be delivered
		else if (!isRetrieving()) {
			isLastSnapshot = true;
		}

		this.pageSize = pageSize;
		snapshot.clear();
		for (int i = validRowPosition; i < materializedTable.size(); i++) {
			snapshot.add(materializedTable.get(i));
		}

		// at least one page
		pageCount = Math.max(1, (int) Math.ceil(((double) snapshot.size() / pageSize)));

		return TypedResult.payload(pageCount);
	}
}
 
Example #24
Source File: CliTableauResultViewTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailedBatchResult() {
	ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, true);

	TestingExecutor mockExecutor = new TestingExecutorBuilder()
		.setSnapshotResultSupplier(
			() -> TypedResult.payload(1),
			TypedResult::endOfStream
		)
		.setResultPageSupplier(() -> {
			throw new SqlExecutionException("query failed");
		})
		.build();

	CliTableauResultView view = new CliTableauResultView(
			terminal, mockExecutor, "session", resultDescriptor);

	try {
		view.displayBatchResults();
		Assert.fail("Shouldn't get here");
	} catch (SqlExecutionException e) {
		Assert.assertEquals("query failed", e.getMessage());
	}
	view.close();

	assertThat(mockExecutor.getNumCancelCalls(), is(1));
}
 
Example #25
Source File: CliTableauResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
private List<Row> waitBatchResults() {
	List<Row> resultRows;
	// take snapshot and make all results in one page
	do {
		try {
			Thread.sleep(50);
		} catch (InterruptedException e) {
			Thread.currentThread().interrupt();
		}
		TypedResult<Integer> result = sqlExecutor.snapshotResult(
				sessionId,
				resultDescriptor.getResultId(),
				Integer.MAX_VALUE);

		if (result.getType() == TypedResult.ResultType.EOS) {
			resultRows = Collections.emptyList();
			break;
		} else if (result.getType() == TypedResult.ResultType.PAYLOAD) {
			resultRows = sqlExecutor.retrieveResultPage(resultDescriptor.getResultId(), 1);
			break;
		} else {
			// result not retrieved yet
		}
	} while (true);

	return resultRows;
}
 
Example #26
Source File: CliTableResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected void refresh() {
	// take snapshot
	TypedResult<Integer> result;
	try {
		result = client.getExecutor().snapshotResult(client.getSessionId(), resultDescriptor.getResultId(), getVisibleMainHeight());
	} catch (SqlExecutionException e) {
		close(e);
		return;
	}

	// stop retrieval if job is done
	if (result.getType() == TypedResult.ResultType.EOS) {
		stopRetrieval(false);
	}
	// update page
	else if (result.getType() == TypedResult.ResultType.PAYLOAD) {
		int newPageCount = result.getPayload();
		pageCount = newPageCount;
		if (page > newPageCount) {
			page = LAST_PAGE;
		}
		updatePage();
	}

	lastRetrieval = LocalTime.now();

	// reset view
	resetAllParts();
}
 
Example #27
Source File: CliResultViewTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void testResultViewClearResult(TypedResult<?> typedResult, boolean isTableMode, int expectedCancellationCount) throws Exception {
	final CountDownLatch cancellationCounterLatch = new CountDownLatch(expectedCancellationCount);
	final SessionContext session = new SessionContext("test-session", new Environment());
	final MockExecutor executor = new MockExecutor(typedResult, cancellationCounterLatch);
	String sessionId = executor.openSession(session);
	final ResultDescriptor descriptor = new ResultDescriptor(
			"result-id",
			TableSchema.builder().field("Null Field", Types.STRING()).build(),
			false,
			false);

	Thread resultViewRunner = null;
	CliClient cli = null;
	try {
		cli = new CliClient(
				TerminalUtils.createDummyTerminal(),
				sessionId,
				executor,
				File.createTempFile("history", "tmp").toPath());
		resultViewRunner = new Thread(new TestingCliResultView(cli, descriptor, isTableMode));
		resultViewRunner.start();
	} finally {
		if (resultViewRunner != null && !resultViewRunner.isInterrupted()) {
			resultViewRunner.interrupt();
		}
		if (cli != null) {
			cli.close();
		}
	}

	assertTrue(
		"Invalid number of cancellations.",
		cancellationCounterLatch.await(10, TimeUnit.SECONDS));
}
 
Example #28
Source File: CliTableauResultViewTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailedStreamingResult() {
	ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, true);

	TestingExecutor mockExecutor = new TestingExecutorBuilder()
		.setResultChangesSupplier(
			() -> TypedResult.payload(streamingData.subList(0, streamingData.size() / 2)),
			() -> {
				throw new SqlExecutionException("query failed");
			})
		.build();

	CliTableauResultView view = new CliTableauResultView(
			terminal, mockExecutor, "session", resultDescriptor);

	try {
		view.displayStreamResults();
		Assert.fail("Shouldn't get here");
	} catch (SqlExecutionException e) {
		Assert.assertEquals("query failed", e.getMessage());
	}
	view.close();

	Assert.assertEquals(
			"+-----+---------+-------------+----------------------+----------------------+----------------+----------------------------+" + System.lineSeparator() +
			"| +/- | boolean |         int |               bigint |              varchar | decimal(10, 5) |                  timestamp |" + System.lineSeparator() +
			"+-----+---------+-------------+----------------------+----------------------+----------------+----------------------------+" + System.lineSeparator() +
			"|   + |  (NULL) |           1 |                    2 |                  abc |           1.23 |      2020-03-01 18:39:14.0 |" + System.lineSeparator() +
			"|   - |   false |      (NULL) |                    0 |                      |              1 |      2020-03-01 18:39:14.1 |" + System.lineSeparator() +
			"|   + |    true |  2147483647 |               (NULL) |              abcdefg |     1234567890 |     2020-03-01 18:39:14.12 |" + System.lineSeparator() +
			"|   - |   false | -2147483648 |  9223372036854775807 |               (NULL) |    12345.06789 |    2020-03-01 18:39:14.123 |" + System.lineSeparator(),
			terminalOutput.toString());
	assertThat(mockExecutor.getNumCancelCalls(), is(1));
}
 
Example #29
Source File: CliTableauResultViewTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testBatchResult() {
	ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, true);

	TestingExecutor mockExecutor = new TestingExecutorBuilder()
		.setSnapshotResultSupplier(
				() -> TypedResult.payload(1),
				TypedResult::endOfStream)
		.setResultPageSupplier(() -> data)
		.build();

	CliTableauResultView view = new CliTableauResultView(
			terminal, mockExecutor, "session", resultDescriptor);

	view.displayBatchResults();
	view.close();
	Assert.assertEquals(
			"+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+" + System.lineSeparator() +
			"| boolean |         int |               bigint |                        varchar | decimal(10, 5) |                  timestamp |" + System.lineSeparator() +
			"+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+" + System.lineSeparator() +
			"|  (NULL) |           1 |                    2 |                            abc |           1.23 |      2020-03-01 18:39:14.0 |" + System.lineSeparator() +
			"|   false |      (NULL) |                    0 |                                |              1 |      2020-03-01 18:39:14.1 |" + System.lineSeparator() +
			"|    true |  2147483647 |               (NULL) |                        abcdefg |     1234567890 |     2020-03-01 18:39:14.12 |" + System.lineSeparator() +
			"|   false | -2147483648 |  9223372036854775807 |                         (NULL) |    12345.06789 |    2020-03-01 18:39:14.123 |" + System.lineSeparator() +
			"|    true |         100 | -9223372036854775808 |                     abcdefg111 |         (NULL) | 2020-03-01 18:39:14.123456 |" + System.lineSeparator() +
			"|  (NULL) |          -1 |                   -1 |     abcdefghijklmnopqrstuvwxyz |   -12345.06789 |                     (NULL) |" + System.lineSeparator() +
			"|  (NULL) |          -1 |                   -1 |                   这是一段中文 |   -12345.06789 |      2020-03-04 18:39:14.0 |" + System.lineSeparator() +
			"|  (NULL) |          -1 |                   -1 |  これは日本語をテストするた... |   -12345.06789 |      2020-03-04 18:39:14.0 |" + System.lineSeparator() +
			"+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+" + System.lineSeparator() +
			"8 rows in set" + System.lineSeparator(),
			terminalOutput.toString());
	assertThat(mockExecutor.getNumCancelCalls(), is(0));
}
 
Example #30
Source File: CliTableauResultViewTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCancelBatchResult() throws Exception {
	ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, true);

	TestingExecutor mockExecutor = new TestingExecutorBuilder()
		.setSnapshotResultSupplier(TypedResult::empty)
		.build();

	CliTableauResultView view = new CliTableauResultView(
			terminal, mockExecutor, "session", resultDescriptor);

	// submit result display in another thread
	ExecutorService executorService = Executors.newSingleThreadExecutor();
	Future<?> furture = executorService.submit(view::displayBatchResults);

	// wait until we trying to get batch result
	CommonTestUtils.waitUntilCondition(
		() -> mockExecutor.getNumSnapshotResultCalls() > 0,
		Deadline.now().plus(Duration.ofSeconds(5)),
		50L);

	// send signal to cancel
	terminal.raise(Terminal.Signal.INT);
	furture.get(5, TimeUnit.SECONDS);

	Assert.assertEquals("Query terminated" + System.lineSeparator(), terminalOutput.toString());
	// didn't have a chance to read page
	assertThat(mockExecutor.getNumRetrieveResultPageCalls(), is(0));
	// tried to cancel query
	assertThat(mockExecutor.getNumCancelCalls(), is(1));

	view.close();
}