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

The following examples show how to use org.apache.flink.table.client.gateway.ResultDescriptor. 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 with Apache License 2.0 6 votes vote down vote up
private void executeStreamQueryTable(
		Map<String, String> replaceVars,
		String query,
		List<String> expectedResults) throws Exception {

	final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
	final SessionContext session = new SessionContext("test-session", new Environment());

	try {
		// start job and retrieval
		final ResultDescriptor desc = executor.executeQuery(session, query);

		assertTrue(desc.isMaterialized());

		final List<String> actualResults = retrieveTableResult(executor, session, desc.getResultId());

		TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
	} finally {
		executor.stop(session);
	}
}
 
Example #2
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 #3
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private void executeStreamQueryTable(
		Map<String, String> replaceVars,
		String query,
		List<String> expectedResults) throws Exception {

	final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
	final SessionContext session = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(session);
	assertEquals("test-session", sessionId);

	try {
		// start job and retrieval
		final ResultDescriptor desc = executor.executeQuery(sessionId, query);

		assertTrue(desc.isMaterialized());

		final List<String> actualResults = retrieveTableResult(executor, sessionId, desc.getResultId());

		TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
	} finally {
		executor.closeSession(sessionId);
	}
}
 
Example #4
Source File: LocalExecutorITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private void executeStreamQueryTable(
		Map<String, String> replaceVars,
		String query,
		List<String> expectedResults) throws Exception {

	final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
	final SessionContext session = new SessionContext("test-session", new Environment());

	try {
		// start job and retrieval
		final ResultDescriptor desc = executor.executeQuery(session, query);

		assertTrue(desc.isMaterialized());

		final List<String> actualResults = retrieveTableResult(executor, session, desc.getResultId());

		TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
	} finally {
		executor.stop(session);
	}
}
 
Example #5
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 #6
Source File: CliTableauResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
public CliTableauResultView(
		final Terminal terminal,
		final Executor sqlExecutor,
		final String sessionId,
		final ResultDescriptor resultDescriptor) {
	this.terminal = terminal;
	this.sqlExecutor = sqlExecutor;
	this.sessionId = sessionId;
	this.resultDescriptor = resultDescriptor;
	this.displayResultExecutorService = Executors.newSingleThreadExecutor(new ExecutorThreadFactory("CliTableauResultView"));
}
 
Example #7
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 #8
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 #9
Source File: CliResultViewTest.java    From flink with Apache License 2.0 5 votes vote down vote up
public TestingCliResultView(
	CliClient client,
	ResultDescriptor descriptor,
	boolean isTableMode) {

	if (isTableMode) {
		realResultView = new TestingCliTableResultView(client, descriptor);
	} else {
		realResultView = new TestingCliChangelogResultView(client, descriptor);
	}
}
 
Example #10
Source File: CliResultViewTest.java    From flink with Apache License 2.0 5 votes vote down vote up
public TestingCliResultView(
	CliClient client,
	ResultDescriptor descriptor,
	boolean isTableMode) {

	if (isTableMode) {
		realResultView = new TestingCliTableResultView(client, descriptor);
	} else {
		realResultView = new TestingCliChangelogResultView(client, descriptor);
	}
}
 
Example #11
Source File: CliResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
public CliResultView(CliClient client, ResultDescriptor resultDescriptor) {
	super(client);
	this.resultDescriptor = resultDescriptor;

	refreshThread = new RefreshThread();
	selectedRow = NO_ROW_SELECTED;
}
 
Example #12
Source File: CliChangelogResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
public CliChangelogResultView(CliClient client, ResultDescriptor resultDescriptor) {
	super(client, resultDescriptor);

	if (client.isPlainTerminal()) {
		refreshInterval = DEFAULT_REFRESH_INTERVAL_PLAIN;
	} else {
		refreshInterval = DEFAULT_REFRESH_INTERVAL;
	}
	previousResults = null;
	// rows are always appended at the tail and deleted from the head of the list
	results = new LinkedList<>();
}
 
Example #13
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();
}
 
Example #14
Source File: CliTableResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
public CliTableResultView(CliClient client, ResultDescriptor resultDescriptor) {
	super(client, resultDescriptor);

	refreshInterval = DEFAULT_REFRESH_INTERVAL;
	pageCount = 1;
	page = LAST_PAGE;

	previousResults = Collections.emptyList();
	previousResultsPage = 1;
	results = Collections.emptyList();
}
 
Example #15
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 #16
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 90_000L)
public void testBatchQueryExecution() throws Exception {
	final URL url = getClass().getClassLoader().getResource("test-data.csv");
	Objects.requireNonNull(url);
	final Map<String, String> replaceVars = new HashMap<>();
	replaceVars.put("$VAR_PLANNER", planner);
	replaceVars.put("$VAR_SOURCE_PATH1", url.getPath());
	replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
	replaceVars.put("$VAR_RESULT_MODE", "table");
	replaceVars.put("$VAR_UPDATE_MODE", "");
	replaceVars.put("$VAR_MAX_ROWS", "100");

	final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
	final SessionContext session = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(session);
	assertEquals("test-session", sessionId);

	try {
		final ResultDescriptor desc = executor.executeQuery(sessionId, "SELECT *, 'ABC' FROM TestView1");

		assertTrue(desc.isMaterialized());

		final List<String> actualResults = retrieveTableResult(executor, sessionId, desc.getResultId());

		final List<String> expectedResults = new ArrayList<>();
		expectedResults.add("47,ABC");
		expectedResults.add("27,ABC");
		expectedResults.add("37,ABC");
		expectedResults.add("37,ABC");
		expectedResults.add("47,ABC");
		expectedResults.add("57,ABC");

		TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
	} finally {
		executor.closeSession(sessionId);
	}
}
 
Example #17
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 90_000L)
public void testBatchQueryExecutionMultipleTimes() throws Exception {
	final URL url = getClass().getClassLoader().getResource("test-data.csv");
	Objects.requireNonNull(url);
	final Map<String, String> replaceVars = new HashMap<>();
	replaceVars.put("$VAR_PLANNER", planner);
	replaceVars.put("$VAR_SOURCE_PATH1", url.getPath());
	replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
	replaceVars.put("$VAR_RESULT_MODE", "table");
	replaceVars.put("$VAR_UPDATE_MODE", "");
	replaceVars.put("$VAR_MAX_ROWS", "100");

	final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
	final SessionContext session = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(session);
	assertEquals("test-session", sessionId);

	final List<String> expectedResults = new ArrayList<>();
	expectedResults.add("47");
	expectedResults.add("27");
	expectedResults.add("37");
	expectedResults.add("37");
	expectedResults.add("47");
	expectedResults.add("57");

	try {
		for (int i = 0; i < 3; i++) {
			final ResultDescriptor desc = executor.executeQuery(sessionId, "SELECT * FROM TestView1");

			assertTrue(desc.isMaterialized());

			final List<String> actualResults = retrieveTableResult(executor, sessionId, desc.getResultId());

			TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
		}
	} finally {
		executor.closeSession(sessionId);
	}
}
 
Example #18
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 90_000L)
public void ensureExceptionOnFaultySourceInStreamingChangelogMode() throws Exception {
	final String missingFileName = "missing-source";

	final Map<String, String> replaceVars = new HashMap<>();
	replaceVars.put("$VAR_PLANNER", planner);
	replaceVars.put("$VAR_SOURCE_PATH1", "missing-source");
	replaceVars.put("$VAR_EXECUTION_TYPE", "streaming");
	replaceVars.put("$VAR_RESULT_MODE", "changelog");
	replaceVars.put("$VAR_UPDATE_MODE", "update-mode: append");
	replaceVars.put("$VAR_MAX_ROWS", "100");
	replaceVars.put("$VAR_RESTART_STRATEGY_TYPE", "none");

	final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
	final SessionContext session = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(session);
	assertEquals("test-session", sessionId);

	Optional<Throwable> throwableWithMessage = Optional.empty();
	try {
		final ResultDescriptor desc = executor.executeQuery(sessionId, "SELECT * FROM TestView1");
		retrieveChangelogResult(executor, sessionId, desc.getResultId());
	} catch (SqlExecutionException e) {
		throwableWithMessage = findMissingFileException(e, missingFileName);
	} finally {
		executor.closeSession(sessionId);
	}
	assertTrue(throwableWithMessage.isPresent());
}
 
Example #19
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 90_000L)
public void ensureExceptionOnFaultySourceInStreamingTableMode() throws Exception {
	final String missingFileName = "missing-source";

	final Map<String, String> replaceVars = new HashMap<>();
	replaceVars.put("$VAR_PLANNER", planner);
	replaceVars.put("$VAR_SOURCE_PATH1", missingFileName);
	replaceVars.put("$VAR_EXECUTION_TYPE", "streaming");
	replaceVars.put("$VAR_RESULT_MODE", "table");
	replaceVars.put("$VAR_UPDATE_MODE", "update-mode: append");
	replaceVars.put("$VAR_MAX_ROWS", "1");
	replaceVars.put("$VAR_RESTART_STRATEGY_TYPE", "none");

	final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
	final SessionContext session = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(session);
	assertEquals("test-session", sessionId);

	Optional<Throwable> throwableWithMessage = Optional.empty();
	try {
		final ResultDescriptor desc = executor.executeQuery(sessionId, "SELECT * FROM TestView1");
		retrieveTableResult(executor, sessionId, desc.getResultId());
	} catch (SqlExecutionException e) {
		throwableWithMessage = findMissingFileException(e, missingFileName);
	} finally {
		executor.closeSession(sessionId);
	}
	assertTrue(throwableWithMessage.isPresent());
}
 
Example #20
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 90_000L)
public void ensureExceptionOnFaultySourceInBatch() throws Exception {
	final String missingFileName = "missing-source";

	final Map<String, String> replaceVars = new HashMap<>();
	replaceVars.put("$VAR_PLANNER", planner);
	replaceVars.put("$VAR_SOURCE_PATH1", missingFileName);
	replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
	replaceVars.put("$VAR_RESULT_MODE", "table");
	replaceVars.put("$VAR_UPDATE_MODE", "");
	replaceVars.put("$VAR_MAX_ROWS", "100");
	replaceVars.put("$VAR_RESTART_STRATEGY_TYPE", "none");

	final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
	final SessionContext session = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(session);
	assertEquals("test-session", sessionId);

	Optional<Throwable> throwableWithMessage = Optional.empty();
	try {
		final ResultDescriptor desc = executor.executeQuery(sessionId, "SELECT * FROM TestView1");
		retrieveTableResult(executor, sessionId, desc.getResultId());
	} catch (SqlExecutionException e) {
		throwableWithMessage = findMissingFileException(e, missingFileName);
	} finally {
		executor.closeSession(sessionId);
	}
	assertTrue(throwableWithMessage.isPresent());
}
 
Example #21
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 30_000L)
public void testBatchQueryExecution() throws Exception {
	final URL url = getClass().getClassLoader().getResource("test-data.csv");
	Objects.requireNonNull(url);
	final Map<String, String> replaceVars = new HashMap<>();
	replaceVars.put("$VAR_PLANNER", planner);
	replaceVars.put("$VAR_SOURCE_PATH1", url.getPath());
	replaceVars.put("$VAR_EXECUTION_TYPE", "batch");
	replaceVars.put("$VAR_RESULT_MODE", "table");
	replaceVars.put("$VAR_UPDATE_MODE", "");
	replaceVars.put("$VAR_MAX_ROWS", "100");

	final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
	final SessionContext session = new SessionContext("test-session", new Environment());

	try {
		final ResultDescriptor desc = executor.executeQuery(session, "SELECT * FROM TestView1");

		assertTrue(desc.isMaterialized());

		final List<String> actualResults = retrieveTableResult(executor, session, desc.getResultId());

		final List<String> expectedResults = new ArrayList<>();
		expectedResults.add("47");
		expectedResults.add("27");
		expectedResults.add("37");
		expectedResults.add("37");
		expectedResults.add("47");
		expectedResults.add("57");

		TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
	} finally {
		executor.stop(session);
	}
}
 
Example #22
Source File: LocalExecutorITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 30_000L)
public void testStreamQueryExecutionChangelog() throws Exception {
	final URL url = getClass().getClassLoader().getResource("test-data.csv");
	Objects.requireNonNull(url);
	final Map<String, String> replaceVars = new HashMap<>();
	replaceVars.put("$VAR_PLANNER", planner);
	replaceVars.put("$VAR_SOURCE_PATH1", url.getPath());
	replaceVars.put("$VAR_EXECUTION_TYPE", "streaming");
	replaceVars.put("$VAR_RESULT_MODE", "changelog");
	replaceVars.put("$VAR_UPDATE_MODE", "update-mode: append");
	replaceVars.put("$VAR_MAX_ROWS", "100");

	final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
	final SessionContext session = new SessionContext("test-session", new Environment());

	try {
		// start job and retrieval
		final ResultDescriptor desc = executor.executeQuery(
			session,
			"SELECT scalarUDF(IntegerField1), StringField1 FROM TableNumber1");

		assertFalse(desc.isMaterialized());

		final List<String> actualResults =
				retrieveChangelogResult(executor, session, desc.getResultId());

		final List<String> expectedResults = new ArrayList<>();
		expectedResults.add("(true,47,Hello World)");
		expectedResults.add("(true,27,Hello World)");
		expectedResults.add("(true,37,Hello World)");
		expectedResults.add("(true,37,Hello World)");
		expectedResults.add("(true,47,Hello World)");
		expectedResults.add("(true,57,Hello World!!!!)");

		TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
	} finally {
		executor.stop(session);
	}
}
 
Example #23
Source File: CliTableResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
public CliTableResultView(CliClient client, ResultDescriptor resultDescriptor) {
	super(client, resultDescriptor);

	refreshInterval = DEFAULT_REFRESH_INTERVAL;
	pageCount = 1;
	page = LAST_PAGE;

	previousResults = Collections.emptyList();
	previousResultsPage = 1;
	results = Collections.emptyList();
}
 
Example #24
Source File: CliChangelogResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
public CliChangelogResultView(CliClient client, ResultDescriptor resultDescriptor) {
	super(client, resultDescriptor);

	if (client.isPlainTerminal()) {
		refreshInterval = DEFAULT_REFRESH_INTERVAL_PLAIN;
	} else {
		refreshInterval = DEFAULT_REFRESH_INTERVAL;
	}
	previousResults = null;
	// rows are always appended at the tail and deleted from the head of the list
	results = new LinkedList<>();
}
 
Example #25
Source File: CliResultView.java    From flink with Apache License 2.0 5 votes vote down vote up
public CliResultView(CliClient client, ResultDescriptor resultDescriptor) {
	super(client);
	this.resultDescriptor = resultDescriptor;

	refreshThread = new RefreshThread();
	selectedRow = NO_ROW_SELECTED;
}
 
Example #26
Source File: CliResultView.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public CliResultView(CliClient client, ResultDescriptor resultDescriptor) {
	super(client);
	this.resultDescriptor = resultDescriptor;

	refreshThread = new RefreshThread();
	selectedRow = NO_ROW_SELECTED;
}
 
Example #27
Source File: CliChangelogResultView.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public CliChangelogResultView(CliClient client, ResultDescriptor resultDescriptor) {
	super(client, resultDescriptor);

	if (client.isPlainTerminal()) {
		refreshInterval = DEFAULT_REFRESH_INTERVAL_PLAIN;
	} else {
		refreshInterval = DEFAULT_REFRESH_INTERVAL;
	}
	previousResults = null;
	// rows are always appended at the tail and deleted from the head of the list
	results = new LinkedList<>();
}
 
Example #28
Source File: CliTableResultView.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public CliTableResultView(CliClient client, ResultDescriptor resultDescriptor) {
	super(client, resultDescriptor);

	refreshInterval = DEFAULT_REFRESH_INTERVAL;
	pageCount = 1;
	page = LAST_PAGE;

	previousResults = Collections.emptyList();
	previousResultsPage = 1;
	results = Collections.emptyList();
}
 
Example #29
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 #30
Source File: LocalExecutorITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 30_000L)
public void testStreamQueryExecutionChangelog() throws Exception {
	final URL url = getClass().getClassLoader().getResource("test-data.csv");
	Objects.requireNonNull(url);
	final Map<String, String> replaceVars = new HashMap<>();
	replaceVars.put("$VAR_SOURCE_PATH1", url.getPath());
	replaceVars.put("$VAR_EXECUTION_TYPE", "streaming");
	replaceVars.put("$VAR_RESULT_MODE", "changelog");
	replaceVars.put("$VAR_UPDATE_MODE", "update-mode: append");
	replaceVars.put("$VAR_MAX_ROWS", "100");

	final Executor executor = createModifiedExecutor(clusterClient, replaceVars);
	final SessionContext session = new SessionContext("test-session", new Environment());

	try {
		// start job and retrieval
		final ResultDescriptor desc = executor.executeQuery(
			session,
			"SELECT scalarUDF(IntegerField1), StringField1 FROM TableNumber1");

		assertFalse(desc.isMaterialized());

		final List<String> actualResults =
				retrieveChangelogResult(executor, session, desc.getResultId());

		final List<String> expectedResults = new ArrayList<>();
		expectedResults.add("(true,47,Hello World)");
		expectedResults.add("(true,27,Hello World)");
		expectedResults.add("(true,37,Hello World)");
		expectedResults.add("(true,37,Hello World)");
		expectedResults.add("(true,47,Hello World)");
		expectedResults.add("(true,57,Hello World!!!!)");

		TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
	} finally {
		executor.stop(session);
	}
}