Search in sources :

Example 6 with ClobImpl

use of org.teiid.core.types.ClobImpl in project teiid by teiid.

the class GeometryUtils method geometryToGml.

public static ClobType geometryToGml(CommandContext ctx, GeometryType geometry, boolean withGmlPrefix) throws FunctionExecutionException {
    Geometry jtsGeometry = getGeometry(geometry);
    GMLWriter writer = new GMLWriter();
    if (!withGmlPrefix) {
        if (geometry.getSrid() != SRID_4326) {
            if (geometry.getSrid() == GeometryType.UNKNOWN_SRID) {
                throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31161));
            }
            jtsGeometry = GeometryTransformUtils.transform(ctx, jtsGeometry, SRID_4326);
        }
        writer.setPrefix(null);
    } else if (geometry.getSrid() != GeometryType.UNKNOWN_SRID) {
    // TODO: should include the srsName
    // writer.setSrsName(String.valueOf(geometry.getSrid()));
    }
    String gmlText = writer.write(jtsGeometry);
    return new ClobType(new ClobImpl(gmlText));
}
Also used : ClobType(org.teiid.core.types.ClobType) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) GMLWriter(com.vividsolutions.jts.io.gml2.GMLWriter) ClobImpl(org.teiid.core.types.ClobImpl)

Example 7 with ClobImpl

use of org.teiid.core.types.ClobImpl in project teiid by teiid.

the class JSONFunctionMethods method jsonParse.

@TeiidFunction(category = FunctionCategoryConstants.JSON)
public static ClobType jsonParse(BlobType val, boolean wellformed) throws SQLException, IOException, ParseException {
    InputStreamReader r = XMLSystemFunctions.getJsonReader(val);
    try {
        if (!wellformed) {
            JSONParser parser = new JSONParser();
            parser.parse(r, validatingContentHandler);
        }
        ClobImpl clobImpl = new ClobImpl();
        clobImpl.setStreamFactory(new InputStreamFactory.BlobInputStreamFactory(val.getReference()));
        clobImpl.setEncoding(r.getEncoding());
        ClobType ct = new ClobType(clobImpl);
        ct.setType(Type.JSON);
        return ct;
    } finally {
        r.close();
    }
}
Also used : ClobType(org.teiid.core.types.ClobType) InputStreamReader(java.io.InputStreamReader) JSONParser(org.teiid.json.simple.JSONParser) InputStreamFactory(org.teiid.core.types.InputStreamFactory) FileStoreInputStreamFactory(org.teiid.common.buffer.FileStoreInputStreamFactory) ClobImpl(org.teiid.core.types.ClobImpl)

Example 8 with ClobImpl

use of org.teiid.core.types.ClobImpl in project teiid by teiid.

the class TestObjectDecoderInputStream method testReplaceObject.

@Test
public void testReplaceObject() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectEncoderOutputStream out = new ObjectEncoderOutputStream(new DataOutputStream(baos), 512);
    ClobImpl clob = new ClobImpl(new InputStreamFactory() {

        @Override
        public InputStream getInputStream() throws IOException {
            // $NON-NLS-1$
            return new ReaderInputStream(new StringReader("Clob contents"), Charset.forName(Streamable.ENCODING));
        }
    }, -1);
    out.writeObject(clob);
    ObjectDecoderInputStream in = new ObjectDecoderInputStream(new AccessibleBufferedInputStream(new ByteArrayInputStream(baos.toByteArray()), 1024), Thread.currentThread().getContextClassLoader(), 1024);
    Object result = in.readObject();
    assertTrue(result instanceof ClobImpl);
}
Also used : DataOutputStream(java.io.DataOutputStream) AccessibleBufferedInputStream(org.teiid.core.util.AccessibleBufferedInputStream) ReaderInputStream(org.teiid.core.util.ReaderInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) InputStreamFactory(org.teiid.core.types.InputStreamFactory) AccessibleBufferedInputStream(org.teiid.core.util.AccessibleBufferedInputStream) ReaderInputStream(org.teiid.core.util.ReaderInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) StringReader(java.io.StringReader) ClobImpl(org.teiid.core.types.ClobImpl) Test(org.junit.Test)

Example 9 with ClobImpl

use of org.teiid.core.types.ClobImpl in project teiid by teiid.

the class TestMongoDBQueryExecution method testGeoFunctionInWhereWithGeometry.

@Test
public void testGeoFunctionInWhereWithGeometry() throws Exception {
    Table table = this.utility.createRuntimeMetadata().getTable("northwind.Categories");
    NamedTable namedTable = new NamedTable("Categories", "g0", table);
    ColumnReference colRef = new ColumnReference(namedTable, "CategoryName", table.getColumnByName("CategoryName"), String.class);
    DerivedColumn col = new DerivedColumn("CategoryName", colRef);
    Select select = new Select();
    select.setDerivedColumns(Arrays.asList(col));
    List<TableReference> tables = new ArrayList<TableReference>();
    tables.add(namedTable);
    select.setFrom(tables);
    final GeometryType geo = GeometryUtils.geometryFromClob(new ClobType(new ClobImpl("POLYGON ((1.0 2.0,3.0 4.0,5.0 6.0,1.0 2.0))")));
    Function function = new // $NON-NLS-1$
    Function(// $NON-NLS-1$
    "mongo.geoWithin", // $NON-NLS-1$
    Arrays.asList(colRef, new Literal(geo, GeometryType.class)), // $NON-NLS-2$
    Boolean.class);
    function.setMetadataObject(getFunctionMethod("mongo.geoWithin"));
    Comparison c = new Comparison(function, new Literal(true, Boolean.class), Comparison.Operator.EQ);
    select.setWhere(c);
    DBCollection dbCollection = helpExecute(select, new String[] { "Categories" }, 2);
    BasicDBObjectBuilder builder = new BasicDBObjectBuilder();
    builder.push("CategoryName");
    // $NON-NLS-1$
    builder.push("$geoWithin");
    // $NON-NLS-1$
    builder.add("$geometry", "{\"type\":\"Polygon\",\"coordinates\":[[[1.0,2.0],[3.0,4.0],[5.0,6.0],[1.0,2.0]]]}");
    BasicDBObject result = new BasicDBObject();
    result.append("CategoryName", "$CategoryName");
    List<DBObject> pipeline = buildArray(new BasicDBObject("$match", builder.get()), new BasicDBObject("$project", result));
    Mockito.verify(dbCollection).aggregate(Mockito.eq(pipeline), Mockito.any(AggregationOptions.class));
}
Also used : NamedTable(org.teiid.language.NamedTable) NamedTable(org.teiid.language.NamedTable) Table(org.teiid.metadata.Table) ArrayList(java.util.ArrayList) ClobType(org.teiid.core.types.ClobType) GeometryType(org.teiid.core.types.GeometryType) Function(org.teiid.language.Function) TableReference(org.teiid.language.TableReference) Comparison(org.teiid.language.Comparison) Literal(org.teiid.language.Literal) Select(org.teiid.language.Select) DerivedColumn(org.teiid.language.DerivedColumn) ClobImpl(org.teiid.core.types.ClobImpl) ColumnReference(org.teiid.language.ColumnReference) Test(org.junit.Test)

Example 10 with ClobImpl

use of org.teiid.core.types.ClobImpl in project teiid by teiid.

the class TextTableNode method initReader.

private void initReader() throws ExpressionEvaluationException, BlockedException, TeiidComponentException, TeiidProcessingException {
    setReferenceValues(this.table);
    ClobType file = (ClobType) getEvaluator(Collections.emptyMap()).evaluate(table.getFile(), null);
    if (file == null) {
        return;
    }
    // get the reader
    try {
        // $NON-NLS-1$
        this.systemId = "Unknown";
        if (file.getReference() instanceof ClobImpl) {
            this.systemId = ((ClobImpl) file.getReference()).getStreamFactory().getSystemId();
            if (this.systemId == null) {
                // $NON-NLS-1$
                this.systemId = "Unknown";
            }
        }
        Reader r = file.getCharacterStream();
        if (!(r instanceof BufferedReader)) {
            reader = new BufferedReader(r);
        } else {
            reader = (BufferedReader) r;
        }
    } catch (SQLException e) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30180, e);
    }
    // process the skip field
    if (skip <= 0) {
        return;
    }
    while (textLine < skip) {
        boolean isHeader = textLine == header;
        if (isHeader) {
            StringBuilder line = readLine(DataTypeManager.MAX_STRING_LENGTH * 16, false);
            if (line == null) {
                // just return an empty batch
                reset();
                return;
            }
            processHeader(parseLine(line));
        } else {
            while (readChar() != newLine) {
            }
        }
    }
}
Also used : ClobType(org.teiid.core.types.ClobType) SQLException(java.sql.SQLException) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) ClobImpl(org.teiid.core.types.ClobImpl) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Aggregations

ClobImpl (org.teiid.core.types.ClobImpl)28 ClobType (org.teiid.core.types.ClobType)21 InputStreamFactory (org.teiid.core.types.InputStreamFactory)14 IOException (java.io.IOException)10 Test (org.junit.Test)10 BlobImpl (org.teiid.core.types.BlobImpl)8 SQLException (java.sql.SQLException)7 BlobType (org.teiid.core.types.BlobType)6 SQLXMLImpl (org.teiid.core.types.SQLXMLImpl)6 Blob (java.sql.Blob)5 List (java.util.List)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Reader (java.io.Reader)3 BigInteger (java.math.BigInteger)3 Clob (java.sql.Clob)3 SQLXML (java.sql.SQLXML)3 HashMap (java.util.HashMap)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3