Search in sources :

Example 1 with Endpoint

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);
}
Also used : FileEndpoint(org.apache.apex.malhar.sql.table.FileEndpoint) KafkaEndpoint(org.apache.apex.malhar.sql.table.KafkaEndpoint) Endpoint(org.apache.apex.malhar.sql.table.Endpoint) MessageFormat(org.apache.apex.malhar.sql.table.MessageFormat) CSVMessageFormat(org.apache.apex.malhar.sql.table.CSVMessageFormat) CSVMessageFormat(org.apache.apex.malhar.sql.table.CSVMessageFormat) KafkaEndpoint(org.apache.apex.malhar.sql.table.KafkaEndpoint) FileEndpoint(org.apache.apex.malhar.sql.table.FileEndpoint)

Example 2 with 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();
}
Also used : FileEndpoint(org.apache.apex.malhar.sql.table.FileEndpoint) KafkaEndpoint(org.apache.apex.malhar.sql.table.KafkaEndpoint) Endpoint(org.apache.apex.malhar.sql.table.Endpoint) StreamEndpoint(org.apache.apex.malhar.sql.table.StreamEndpoint) CSVMessageFormat(org.apache.apex.malhar.sql.table.CSVMessageFormat) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) FileEndpoint(org.apache.apex.malhar.sql.table.FileEndpoint) Test(org.junit.Test)

Aggregations

CSVMessageFormat (org.apache.apex.malhar.sql.table.CSVMessageFormat)2 Endpoint (org.apache.apex.malhar.sql.table.Endpoint)2 FileEndpoint (org.apache.apex.malhar.sql.table.FileEndpoint)2 KafkaEndpoint (org.apache.apex.malhar.sql.table.KafkaEndpoint)2 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)1 MessageFormat (org.apache.apex.malhar.sql.table.MessageFormat)1 StreamEndpoint (org.apache.apex.malhar.sql.table.StreamEndpoint)1 Test (org.junit.Test)1