Java Code Examples for org.apache.flink.table.client.SqlClientException

The following examples show how to use org.apache.flink.table.client.SqlClientException. These examples are extracted from open source projects. 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 Project: Flink-CEPplus   Source File: CollectStreamResult.java    License: Apache License 2.0 6 votes vote down vote up
public CollectStreamResult(TypeInformation<Row> outputType, ExecutionConfig config,
		InetAddress gatewayAddress, int gatewayPort) {
	this.outputType = outputType;

	resultLock = new Object();

	// create socket stream iterator
	final TypeInformation<Tuple2<Boolean, Row>> socketType = Types.TUPLE(Types.BOOLEAN, outputType);
	final TypeSerializer<Tuple2<Boolean, Row>> serializer = socketType.createSerializer(config);
	try {
		// pass gateway port and address such that iterator knows where to bind to
		iterator = new SocketStreamIterator<>(gatewayPort, gatewayAddress, serializer);
	} catch (IOException e) {
		throw new SqlClientException("Could not start socket for result retrieval.", e);
	}

	// create table sink
	// pass binding address and port such that sink knows where to send to
	collectTableSink = new CollectStreamTableSink(iterator.getBindAddress(), iterator.getPort(), serializer);
	retrievalThread = new ResultRetrievalThread();
	monitoringThread = new JobMonitoringThread();
}
 
Example 2
Source Project: Flink-CEPplus   Source File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
public static CliOptions parseEmbeddedModeClient(String[] args) {
	try {
		DefaultParser parser = new DefaultParser();
		CommandLine line = parser.parse(EMBEDDED_MODE_CLIENT_OPTIONS, args, true);
		return new CliOptions(
			line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()),
			checkSessionId(line),
			checkUrl(line, CliOptionsParser.OPTION_ENVIRONMENT),
			checkUrl(line, CliOptionsParser.OPTION_DEFAULTS),
			checkUrls(line, CliOptionsParser.OPTION_JAR),
			checkUrls(line, CliOptionsParser.OPTION_LIBRARY),
			line.getOptionValue(CliOptionsParser.OPTION_UPDATE.getOpt())
		);
	}
	catch (ParseException e) {
		throw new SqlClientException(e.getMessage());
	}
}
 
Example 3
Source Project: Flink-CEPplus   Source File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
public static CliOptions parseGatewayModeClient(String[] args) {
	try {
		DefaultParser parser = new DefaultParser();
		CommandLine line = parser.parse(GATEWAY_MODE_CLIENT_OPTIONS, args, true);
		return new CliOptions(
			line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()),
			checkSessionId(line),
			checkUrl(line, CliOptionsParser.OPTION_ENVIRONMENT),
			null,
			checkUrls(line, CliOptionsParser.OPTION_JAR),
			checkUrls(line, CliOptionsParser.OPTION_LIBRARY),
			line.getOptionValue(CliOptionsParser.OPTION_UPDATE.getOpt())
		);
	}
	catch (ParseException e) {
		throw new SqlClientException(e.getMessage());
	}
}
 
Example 4
Source Project: Flink-CEPplus   Source File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
public static CliOptions parseGatewayModeGateway(String[] args) {
	try {
		DefaultParser parser = new DefaultParser();
		CommandLine line = parser.parse(GATEWAY_MODE_GATEWAY_OPTIONS, args, true);
		return new CliOptions(
			line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()),
			null,
			null,
			checkUrl(line, CliOptionsParser.OPTION_DEFAULTS),
			checkUrls(line, CliOptionsParser.OPTION_JAR),
			checkUrls(line, CliOptionsParser.OPTION_LIBRARY),
			null
		);
	}
	catch (ParseException e) {
		throw new SqlClientException(e.getMessage());
	}
}
 
Example 5
Source Project: Flink-CEPplus   Source File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
private static List<URL> checkUrls(CommandLine line, Option option) {
	if (line.hasOption(option.getOpt())) {
		final String[] urls = line.getOptionValues(option.getOpt());
		return Arrays.stream(urls)
			.distinct()
			.map((url) -> {
				try {
					return Path.fromLocalFile(new File(url).getAbsoluteFile()).toUri().toURL();
				} catch (Exception e) {
					throw new SqlClientException("Invalid path for option '" + option.getLongOpt() + "': " + url, e);
				}
			})
			.collect(Collectors.toList());
	}
	return null;
}
 
Example 6
Source Project: flink   Source File: CollectStreamResult.java    License: Apache License 2.0 6 votes vote down vote up
public CollectStreamResult(RowTypeInfo outputType, ExecutionConfig config,
		InetAddress gatewayAddress, int gatewayPort) {
	this.outputType = outputType;

	resultLock = new Object();

	// create socket stream iterator
	final TypeInformation<Tuple2<Boolean, Row>> socketType = Types.TUPLE(Types.BOOLEAN, outputType);
	final TypeSerializer<Tuple2<Boolean, Row>> serializer = socketType.createSerializer(config);
	try {
		// pass gateway port and address such that iterator knows where to bind to
		iterator = new SocketStreamIterator<>(gatewayPort, gatewayAddress, serializer);
	} catch (IOException e) {
		throw new SqlClientException("Could not start socket for result retrieval.", e);
	}

	// create table sink
	// pass binding address and port such that sink knows where to send to
	collectTableSink = new CollectStreamTableSink(iterator.getBindAddress(), iterator.getPort(), serializer)
		.configure(outputType.getFieldNames(), outputType.getFieldTypes());
	retrievalThread = new ResultRetrievalThread();
	monitoringThread = new JobMonitoringThread();
}
 
Example 7
Source Project: flink   Source File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
public static CliOptions parseEmbeddedModeClient(String[] args) {
	try {
		DefaultParser parser = new DefaultParser();
		CommandLine line = parser.parse(EMBEDDED_MODE_CLIENT_OPTIONS, args, true);
		return new CliOptions(
			line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()),
			checkSessionId(line),
			checkUrl(line, CliOptionsParser.OPTION_ENVIRONMENT),
			checkUrl(line, CliOptionsParser.OPTION_DEFAULTS),
			checkUrls(line, CliOptionsParser.OPTION_JAR),
			checkUrls(line, CliOptionsParser.OPTION_LIBRARY),
			line.getOptionValue(CliOptionsParser.OPTION_UPDATE.getOpt())
		);
	}
	catch (ParseException e) {
		throw new SqlClientException(e.getMessage());
	}
}
 
Example 8
Source Project: flink   Source File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
public static CliOptions parseGatewayModeClient(String[] args) {
	try {
		DefaultParser parser = new DefaultParser();
		CommandLine line = parser.parse(GATEWAY_MODE_CLIENT_OPTIONS, args, true);
		return new CliOptions(
			line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()),
			checkSessionId(line),
			checkUrl(line, CliOptionsParser.OPTION_ENVIRONMENT),
			null,
			checkUrls(line, CliOptionsParser.OPTION_JAR),
			checkUrls(line, CliOptionsParser.OPTION_LIBRARY),
			line.getOptionValue(CliOptionsParser.OPTION_UPDATE.getOpt())
		);
	}
	catch (ParseException e) {
		throw new SqlClientException(e.getMessage());
	}
}
 
Example 9
Source Project: flink   Source File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
public static CliOptions parseGatewayModeGateway(String[] args) {
	try {
		DefaultParser parser = new DefaultParser();
		CommandLine line = parser.parse(GATEWAY_MODE_GATEWAY_OPTIONS, args, true);
		return new CliOptions(
			line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()),
			null,
			null,
			checkUrl(line, CliOptionsParser.OPTION_DEFAULTS),
			checkUrls(line, CliOptionsParser.OPTION_JAR),
			checkUrls(line, CliOptionsParser.OPTION_LIBRARY),
			null
		);
	}
	catch (ParseException e) {
		throw new SqlClientException(e.getMessage());
	}
}
 
Example 10
Source Project: flink   Source File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
private static List<URL> checkUrls(CommandLine line, Option option) {
	if (line.hasOption(option.getOpt())) {
		final String[] urls = line.getOptionValues(option.getOpt());
		return Arrays.stream(urls)
			.distinct()
			.map((url) -> {
				try {
					return Path.fromLocalFile(new File(url).getAbsoluteFile()).toUri().toURL();
				} catch (Exception e) {
					throw new SqlClientException("Invalid path for option '" + option.getLongOpt() + "': " + url, e);
				}
			})
			.collect(Collectors.toList());
	}
	return null;
}
 
Example 11
Source Project: flink   Source File: CollectStreamResult.java    License: Apache License 2.0 6 votes vote down vote up
public CollectStreamResult(
		TableSchema tableSchema,
		ExecutionConfig config,
		InetAddress gatewayAddress,
		int gatewayPort,
		ClassLoader classLoader) {
	resultLock = new Object();

	// create socket stream iterator
	final TypeInformation<Tuple2<Boolean, Row>> socketType = Types.TUPLE(Types.BOOLEAN, tableSchema.toRowType());
	final TypeSerializer<Tuple2<Boolean, Row>> serializer = socketType.createSerializer(config);
	try {
		// pass gateway port and address such that iterator knows where to bind to
		iterator = new SocketStreamIterator<>(gatewayPort, gatewayAddress, serializer);
	} catch (IOException e) {
		throw new SqlClientException("Could not start socket for result retrieval.", e);
	}

	// create table sink
	// pass binding address and port such that sink knows where to send to
	collectTableSink = new CollectStreamTableSink(iterator.getBindAddress(), iterator.getPort(), serializer, tableSchema);
	retrievalThread = new ResultRetrievalThread();

	this.classLoader = checkNotNull(classLoader);
}
 
Example 12
Source Project: flink   Source File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
public static CliOptions parseEmbeddedModeClient(String[] args) {
	try {
		DefaultParser parser = new DefaultParser();
		CommandLine line = parser.parse(EMBEDDED_MODE_CLIENT_OPTIONS, args, true);
		return new CliOptions(
			line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()),
			checkSessionId(line),
			checkUrl(line, CliOptionsParser.OPTION_ENVIRONMENT),
			checkUrl(line, CliOptionsParser.OPTION_DEFAULTS),
			checkUrls(line, CliOptionsParser.OPTION_JAR),
			checkUrls(line, CliOptionsParser.OPTION_LIBRARY),
			line.getOptionValue(CliOptionsParser.OPTION_UPDATE.getOpt()),
			line.getOptionValue(CliOptionsParser.OPTION_HISTORY.getOpt()),
			getPythonConfiguration(line)
		);
	}
	catch (ParseException e) {
		throw new SqlClientException(e.getMessage());
	}
}
 
Example 13
Source Project: flink   Source File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
public static CliOptions parseGatewayModeClient(String[] args) {
	try {
		DefaultParser parser = new DefaultParser();
		CommandLine line = parser.parse(GATEWAY_MODE_CLIENT_OPTIONS, args, true);
		return new CliOptions(
			line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()),
			checkSessionId(line),
			checkUrl(line, CliOptionsParser.OPTION_ENVIRONMENT),
			null,
			checkUrls(line, CliOptionsParser.OPTION_JAR),
			checkUrls(line, CliOptionsParser.OPTION_LIBRARY),
			line.getOptionValue(CliOptionsParser.OPTION_UPDATE.getOpt()),
			line.getOptionValue(CliOptionsParser.OPTION_HISTORY.getOpt()),
			getPythonConfiguration(line)
		);
	}
	catch (ParseException e) {
		throw new SqlClientException(e.getMessage());
	}
}
 
Example 14
Source Project: flink   Source File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
public static CliOptions parseGatewayModeGateway(String[] args) {
	try {
		DefaultParser parser = new DefaultParser();
		CommandLine line = parser.parse(GATEWAY_MODE_GATEWAY_OPTIONS, args, true);
		return new CliOptions(
			line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()),
			null,
			null,
			checkUrl(line, CliOptionsParser.OPTION_DEFAULTS),
			checkUrls(line, CliOptionsParser.OPTION_JAR),
			checkUrls(line, CliOptionsParser.OPTION_LIBRARY),
			null,
			null,
			getPythonConfiguration(line)
		);
	}
	catch (ParseException e) {
		throw new SqlClientException(e.getMessage());
	}
}
 
Example 15
Source Project: flink   Source File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
private static List<URL> checkUrls(CommandLine line, Option option) {
	if (line.hasOption(option.getOpt())) {
		final String[] urls = line.getOptionValues(option.getOpt());
		return Arrays.stream(urls)
			.distinct()
			.map((url) -> {
				try {
					return Path.fromLocalFile(new File(url).getAbsoluteFile()).toUri().toURL();
				} catch (Exception e) {
					throw new SqlClientException("Invalid path for option '" + option.getLongOpt() + "': " + url, e);
				}
			})
			.collect(Collectors.toList());
	}
	return null;
}
 
Example 16
Source Project: Flink-CEPplus   Source File: Environment.java    License: Apache License 2.0 5 votes vote down vote up
public void setTables(List<Map<String, Object>> tables) {
	this.tables = new LinkedHashMap<>(tables.size());

	tables.forEach(config -> {
		final TableEntry table = TableEntry.create(config);
		if (this.tables.containsKey(table.getName())) {
			throw new SqlClientException(
				"Cannot create table '" + table.getName() + "' because a table with this name is already registered.");
		}
		this.tables.put(table.getName(), table);
	});
}
 
Example 17
Source Project: Flink-CEPplus   Source File: Environment.java    License: Apache License 2.0 5 votes vote down vote up
public void setFunctions(List<Map<String, Object>> functions) {
	this.functions = new HashMap<>(functions.size());

	functions.forEach(config -> {
		final FunctionEntry function = FunctionEntry.create(config);
		if (this.functions.containsKey(function.getName())) {
			throw new SqlClientException(
				"Cannot create function '" + function.getName() + "' because a function with this name is already registered.");
		}
		this.functions.put(function.getName(), function);
	});
}
 
Example 18
Source Project: Flink-CEPplus   Source File: Environment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses an environment file from an URL.
 */
public static Environment parse(URL url) throws IOException {
	try {
		return new ConfigUtil.LowerCaseYamlMapper().readValue(url, Environment.class);
	} catch (JsonMappingException e) {
		throw new SqlClientException("Could not parse environment file. Cause: " + e.getMessage());
	}
}
 
Example 19
Source Project: Flink-CEPplus   Source File: Environment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses an environment file from an String.
 */
public static Environment parse(String content) throws IOException {
	try {
		return new ConfigUtil.LowerCaseYamlMapper().readValue(content, Environment.class);
	} catch (JsonMappingException e) {
		throw new SqlClientException("Could not parse environment file. Cause: " + e.getMessage());
	}
}
 
Example 20
Source Project: Flink-CEPplus   Source File: ConfigEntry.java    License: Apache License 2.0 5 votes vote down vote up
protected ConfigEntry(DescriptorProperties properties) {
	try {
		validate(properties);
	} catch (ValidationException e) {
		throw new SqlClientException("Invalid configuration entry.", e);
	}

	this.properties = properties;
}
 
Example 21
Source Project: Flink-CEPplus   Source File: TableEntry.java    License: Apache License 2.0 5 votes vote down vote up
private static TableEntry create(DescriptorProperties properties) {
	properties.validateString(TABLES_NAME, false, 1);
	properties.validateEnumValues(
		TABLES_TYPE,
		false,
		Arrays.asList(
			TABLES_TYPE_VALUE_SOURCE,
			TABLES_TYPE_VALUE_SOURCE_TABLE,
			TABLES_TYPE_VALUE_SINK,
			TABLES_TYPE_VALUE_SINK_TABLE,
			TABLES_TYPE_VALUE_BOTH,
			TABLES_TYPE_VALUE_SOURCE_SINK_TABLE,
			TABLES_TYPE_VALUE_VIEW,
			TABLES_TYPE_VALUE_TEMPORAL_TABLE));

	final String name = properties.getString(TABLES_NAME);

	final DescriptorProperties cleanedProperties =
		properties.withoutKeys(Arrays.asList(TABLES_NAME, TABLES_TYPE));

	switch (properties.getString(TABLES_TYPE)) {
		case TABLES_TYPE_VALUE_SOURCE:
		case TABLES_TYPE_VALUE_SOURCE_TABLE:
			return new SourceTableEntry(name, cleanedProperties);
		case TABLES_TYPE_VALUE_SINK:
		case TABLES_TYPE_VALUE_SINK_TABLE:
			return new SinkTableEntry(name, cleanedProperties);
		case TABLES_TYPE_VALUE_BOTH:
		case TABLES_TYPE_VALUE_SOURCE_SINK_TABLE:
			return new SourceSinkTableEntry(name, cleanedProperties);
		case TABLES_TYPE_VALUE_VIEW:
			return new ViewEntry(name, cleanedProperties);
		case TABLES_TYPE_VALUE_TEMPORAL_TABLE:
			return new TemporalTableEntry(name, cleanedProperties);
		default:
			throw new SqlClientException("Unexpected table type.");
	}
}
 
Example 22
Source Project: Flink-CEPplus   Source File: CliOptionsParser.java    License: Apache License 2.0 5 votes vote down vote up
private static String checkSessionId(CommandLine line) {
	final String sessionId = line.getOptionValue(CliOptionsParser.OPTION_SESSION.getOpt());
	if (sessionId != null && !sessionId.matches("[a-zA-Z0-9_\\-.]+")) {
		throw new SqlClientException("Session identifier must only consists of 'a-zA-Z0-9_-.'.");
	}
	return sessionId;
}
 
Example 23
Source Project: Flink-CEPplus   Source File: CliClient.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Closes the CLI instance.
 */
public void close() {
	try {
		terminal.close();
	} catch (IOException e) {
		throw new SqlClientException("Unable to close terminal.", e);
	}
}
 
Example 24
Source Project: Flink-CEPplus   Source File: CliClient.java    License: Apache License 2.0 5 votes vote down vote up
private static Terminal createDefaultTerminal() {
	try {
		return TerminalBuilder.builder()
			.name(CliStrings.CLI_NAME)
			.build();
	} catch (IOException e) {
		throw new SqlClientException("Error opening command line interface.", e);
	}
}
 
Example 25
Source Project: flink   Source File: Environment.java    License: Apache License 2.0 5 votes vote down vote up
public void setCatalogs(List<Map<String, Object>> catalogs) {
	this.catalogs = new HashMap<>(catalogs.size());

	catalogs.forEach(config -> {
		final CatalogEntry catalog = CatalogEntry.create(config);
		if (this.catalogs.containsKey(catalog.getName())) {
			throw new SqlClientException(
				String.format("Cannot create catalog '%s' because a catalog with this name is already registered.",
					catalog.getName()));
		}
		this.catalogs.put(catalog.getName(), catalog);
	});
}
 
Example 26
Source Project: flink   Source File: Environment.java    License: Apache License 2.0 5 votes vote down vote up
public void setTables(List<Map<String, Object>> tables) {
	this.tables = new LinkedHashMap<>(tables.size());

	tables.forEach(config -> {
		final TableEntry table = TableEntry.create(config);
		if (this.tables.containsKey(table.getName())) {
			throw new SqlClientException(
				"Cannot create table '" + table.getName() + "' because a table with this name is already registered.");
		}
		this.tables.put(table.getName(), table);
	});
}
 
Example 27
Source Project: flink   Source File: Environment.java    License: Apache License 2.0 5 votes vote down vote up
public void setFunctions(List<Map<String, Object>> functions) {
	this.functions = new HashMap<>(functions.size());

	functions.forEach(config -> {
		final FunctionEntry function = FunctionEntry.create(config);
		if (this.functions.containsKey(function.getName())) {
			throw new SqlClientException(
				"Cannot create function '" + function.getName() + "' because a function with this name is already registered.");
		}
		this.functions.put(function.getName(), function);
	});
}
 
Example 28
Source Project: flink   Source File: Environment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses an environment file from an URL.
 */
public static Environment parse(URL url) throws IOException {
	try {
		return new ConfigUtil.LowerCaseYamlMapper().readValue(url, Environment.class);
	} catch (JsonMappingException e) {
		throw new SqlClientException("Could not parse environment file. Cause: " + e.getMessage());
	}
}
 
Example 29
Source Project: flink   Source File: Environment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses an environment file from an String.
 */
public static Environment parse(String content) throws IOException {
	try {
		return new ConfigUtil.LowerCaseYamlMapper().readValue(content, Environment.class);
	} catch (JsonMappingException e) {
		throw new SqlClientException("Could not parse environment file. Cause: " + e.getMessage());
	}
}
 
Example 30
Source Project: flink   Source File: ConfigEntry.java    License: Apache License 2.0 5 votes vote down vote up
protected ConfigEntry(DescriptorProperties properties) {
	try {
		validate(properties);
	} catch (ValidationException e) {
		throw new SqlClientException("Invalid configuration entry.", e);
	}

	this.properties = properties;
}