use of org.apache.apex.malhar.sql.table.Endpoint in project apex-malhar by apache.
the class ApexSQLTableFactory method create.
@SuppressWarnings("unchecked")
@Override
public Table create(SchemaPlus schemaPlus, String name, Map<String, Object> operands, RelDataType rowType) {
Endpoint endpoint;
String endpointSystemType = (String) operands.get(Endpoint.ENDPOINT);
if (endpointSystemType.equalsIgnoreCase(Endpoint.EndpointType.FILE.name())) {
endpoint = new FileEndpoint();
} else if (endpointSystemType.equalsIgnoreCase(Endpoint.EndpointType.KAFKA.name())) {
endpoint = new KafkaEndpoint();
} else {
throw new RuntimeException("Cannot find endpoint");
}
endpoint.setEndpointOperands((Map<String, Object>) operands.get(Endpoint.SYSTEM_OPERANDS));
MessageFormat mf;
String messageFormat = (String) operands.get(MessageFormat.MESSAGE_FORMAT);
if (messageFormat.equalsIgnoreCase(MessageFormat.MessageFormatType.CSV.name())) {
mf = new CSVMessageFormat();
} else {
throw new RuntimeException("Cannot find message format");
}
mf.setMessageFormatOperands((Map<String, Object>) operands.get(MessageFormat.MESSAGE_FORMAT_OPERANDS));
endpoint.setMessageFormat(mf);
return new ApexSQLTable(schemaPlus, name, operands, rowType, endpoint);
}
use of org.apache.apex.malhar.sql.table.Endpoint in project apex-malhar by apache.
the class SerDeTest method testSQLWithAPI.
@Test
public void testSQLWithAPI() throws ClassNotFoundException, IOException {
LogicalPlan dag = new LogicalPlan();
String schema = "{\"separator\":\",\",\"quoteChar\":\"\\\"\",\"fields\":[" + "{\"name\":\"RowTime\",\"type\":\"Date\",\"constraints\":{\"format\":\"dd/MM/yyyy hh:mm:ss Z\"}}," + "{\"name\":\"id\",\"type\":\"Integer\"},{\"name\":\"Product\",\"type\":\"String\"}," + "{\"name\":\"units\",\"type\":\"Integer\"}]}";
Endpoint endpoint = new FileEndpoint("dummyFilePath", new CSVMessageFormat(schema));
SQLExecEnvironment.getEnvironment().registerTable("ORDERS", endpoint).executeSQL(dag, "SELECT STREAM FLOOR(ROWTIME TO HOUR), SUBSTRING(PRODUCT, 0, 5) FROM ORDERS WHERE id > 3");
dag.validate();
}
Aggregations