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

The following examples show how to use org.apache.flink.table.client.SqlClientException. 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: CollectStreamResult.java    From Flink-CEPplus with 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 File: CollectStreamResult.java    From flink with 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 #3
Source File: CliOptionsParser.java    From flink with 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 #4
Source File: CliOptionsParser.java    From flink with 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 File: CliOptionsParser.java    From flink with 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 #6
Source File: CliOptionsParser.java    From flink with 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 #7
Source File: CollectStreamResult.java    From flink with 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 #8
Source File: CliOptionsParser.java    From flink with 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 #9
Source File: CliOptionsParser.java    From flink with 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 #10
Source File: CliOptionsParser.java    From flink with 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 #11
Source File: CliOptionsParser.java    From flink with 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 #12
Source File: CliOptionsParser.java    From Flink-CEPplus with 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 #13
Source File: CliOptionsParser.java    From Flink-CEPplus with 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 #14
Source File: CliOptionsParser.java    From Flink-CEPplus with 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 #15
Source File: CliOptionsParser.java    From Flink-CEPplus with 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 File: EnvironmentTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicateCatalog() {
	exception.expect(SqlClientException.class);
	exception.expectMessage("Cannot create catalog 'catalog2' because a catalog with this name is already registered.");
	Environment env = new Environment();
	env.setCatalogs(Arrays.asList(
		createCatalog("catalog1", "test"),
		createCatalog("catalog2", "test"),
		createCatalog("catalog2", "test")));
}
 
Example #17
Source File: EnvironmentTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicateModules() {
	exception.expect(SqlClientException.class);
	Environment env = new Environment();
	env.setModules(Arrays.asList(
		createModule("module1", "test"),
		createModule("module2", "test"),
		createModule("module2", "test")));
}
 
Example #18
Source File: Environment.java    From flink with Apache License 2.0 5 votes vote down vote up
public void setModules(List<Map<String, Object>> modules) {
	this.modules = new LinkedHashMap<>(modules.size());

	modules.forEach(config -> {
		final ModuleEntry entry = ModuleEntry.create(config);
		if (this.modules.containsKey(entry.getName())) {
			throw new SqlClientException(
				String.format("Cannot register module '%s' because a module with this name is already registered.",
					entry.getName()));
		}
		this.modules.put(entry.getName(), entry);
	});
}
 
Example #19
Source File: EnvironmentTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicateCatalog() {
	exception.expect(SqlClientException.class);
	exception.expectMessage("Cannot create catalog 'catalog2' because a catalog with this name is already registered.");
	Environment env = new Environment();
	env.setCatalogs(Arrays.asList(
		createCatalog("catalog1", "test"),
		createCatalog("catalog2", "test"),
		createCatalog("catalog2", "test")));
}
 
Example #20
Source File: CliClient.java    From flink with 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 #21
Source File: CliClient.java    From flink with 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 #22
Source File: CliOptionsParser.java    From flink with Apache License 2.0 5 votes vote down vote up
private static Configuration getPythonConfiguration(CommandLine line) {
	try {
		Class<?> clazz = Class.forName(
			"org.apache.flink.python.util.PythonDependencyUtils",
			true,
			Thread.currentThread().getContextClassLoader());
		Method parsePythonDependencyConfiguration =
			clazz.getMethod("parsePythonDependencyConfiguration", CommandLine.class);
		return (Configuration) parsePythonDependencyConfiguration.invoke(null, line);
	} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
		throw new SqlClientException("Failed to parse the Python command line options.", e);
	}
}
 
Example #23
Source File: Environment.java    From flink with 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 #24
Source File: Environment.java    From flink with 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 #25
Source File: Environment.java    From flink with 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 #26
Source File: Environment.java    From flink with 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 #27
Source File: Environment.java    From flink with 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 #28
Source File: ConfigEntry.java    From flink with 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 #29
Source File: TableEntry.java    From flink with 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 #30
Source File: CliOptionsParser.java    From flink with 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;
}