@Test public void testRegexpReplaceOkay() throws Exception { // Test replace-first vs replace-all. assertEval("regexp_replace('foobarbaz', 'b..', 'X')", "fooXbaz"); assertEval("regexp_replace('foobarbaz', 'b..', 'X', 'g')", "fooXX"); // Test replace-all with capture group. assertEval("regexp_replace('foobarbaz', 'b(..)', 'X$1Y', 'g')", "fooXarYXazY"); // Test case-insensitive matching. assertEval("regexp_replace('fooBARbaz', 'a', 'X', 'g')", "fooBARbXz"); assertEval("regexp_replace('fooBARbaz', 'a', 'X', 'gi')", "fooBXRbXz"); // Test multiline. assertEval("regexp_replace('foo\nbar\nbaz', '(b[\\d\\w\\s]+?)$', 'X', 'g')", "foo\nX"); assertEval("regexp_replace('foo\nbar\nbaz', '(b[\\d\\w\\s]+?)$', 'X', 'gm')", "foo\nX\nX"); }
@Test(expected=QueryResolverException.class) public void testStringAggWrongTypes() throws Exception { String sql = "string_agg(pm1.g1.e1, pm1.g1.e2)"; //$NON-NLS-1$ getExpression(sql); }
/** * Should resolve using varags logic */ @Test public void testResolveCoalesce1a() throws Exception { String sql = "coalesce('', '', '', '')"; //$NON-NLS-1$ helpResolveFunction(sql); }
@Test(expected=QueryResolverException.class) public void testStringAggWrongArgs() throws Exception { String sql = "string_agg(pm1.g1.e1)"; //$NON-NLS-1$ getExpression(sql); }
@Test public void testIsDistinct() throws Exception { assertEval("'a' is distinct from 'b'", "true"); assertEval("'a' is not distinct from 'b'", "false"); assertEval("('a', null) is not distinct from ('a', null)", "true"); }
/** * Should resolve as 1 is implicitly convertable to string */ @Test public void testResolveCoalesce2() throws Exception { String sql = "coalesce('', 1, '', '')"; //$NON-NLS-1$ helpResolveFunction(sql); }
@Test public void testToCharsBytesWellformed() throws Exception { Expression ex = TestFunctionResolving.getExpression("to_chars(to_bytes('abc', 'utf-8', false), 'utf-8', true)"); assertEquals("abc", ((Clob)Evaluator.evaluate(ex)).getSubString(1, 3)); try { ex = TestFunctionResolving.getExpression("to_bytes('\u00ff', 'ascii', false))"); Evaluator.evaluate(ex); fail("expected exception"); } catch (ExpressionEvaluationException e) { } TestFunctionResolving.getExpression("to_bytes('\u00ff', 'ascii', false))"); }
@Test public void testAsEwkt() throws Exception { assertEval("ST_AsEWKT(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))', 4326))", "SRID=4326;POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))"); assertEval("ST_AsEWKT(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))'))", "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))"); }
@Test public void testResolveCoalesce1() throws Exception { String sql = "coalesce('', '', '')"; //$NON-NLS-1$ helpResolveFunction(sql); }
@Test public void testEwktWithSRID() throws Exception { Expression ex = TestFunctionResolving.getExpression("st_asewkt(ST_GeomFromEwkt('SRID=4326;POINT(0 0)')))"); Evaluator.evaluate(ex); //whitespace ex = TestFunctionResolving.getExpression("st_asewkt(ST_GeomFromEwkt(' SRID=4326;POINT(0 0)')))"); Evaluator.evaluate(ex); //mixed case ex = TestFunctionResolving.getExpression("st_asewkt(ST_GeomFromEwkt('SrID=4326;POINT(0 0)')))"); assertEquals("SRID=4326;POINT (0 0)", ClobType.getString((ClobType)Evaluator.evaluate(ex))); }
@Test public void testAsGeoJson() throws Exception { assertEval( "ST_AsGeoJson(ST_GeomFromText('POINT (-48.23456 20.12345)'))", "{\"type\":\"Point\",\"coordinates\":[-48.23456,20.12345]}" ); assertEval( "ST_AsGeoJson(ST_GeomFromText('POLYGON ((40 0, 50 50, 0 50, 0 0, 40 0))'))", "{\"type\":\"Polygon\",\"coordinates\":[[[40.0,0.0],[50.0,50.0],[0.0,50.0],[0.0,0.0],[40.0,0.0]]]}" ); }
@Test public void testResolveCoalesce() throws Exception { String sql = "coalesce('', '')"; //$NON-NLS-1$ helpResolveFunction(sql); }
private Function helpResolveFunction(String sql) throws QueryParserException, QueryResolverException, TeiidComponentException { Function func = (Function)getExpression(sql); assertEquals(DataTypeManager.DefaultDataClasses.STRING, func.getType()); return func; }
@Test public void testFromGeoJson() throws Exception { assertEval( "ST_AsText(ST_GeomFromGeoJSON('{\"coordinates\":[-48.23456,20.12345],\"type\":\"Point\"}'))", "POINT (-48.23456 20.12345)" ); assertEval( "ST_AsText(ST_GeomFromGeoJSON('{\"coordinates\":[[[40.0,0.0],[50.0,50.0],[0.0,50.0],[0.0,0.0],[40.0,0.0]]],\"type\":\"Polygon\"}'))", "POLYGON ((40 0, 50 50, 0 50, 0 0, 40 0))" ); }
@Test public void testResolveCoalesce3() throws Exception { String sql = "coalesce('', 1, null, '')"; //$NON-NLS-1$ helpResolveFunction(sql); }
@Test(expected=ExpressionEvaluationException.class) public void testEwktNotExpected() throws Exception { Expression ex = TestFunctionResolving.getExpression("ST_GeomFromText('POINT(0 0 0)'))"); Evaluator.evaluate(ex); }
@Test public void testAsGml() throws Exception { assertEval( "ST_AsGML(ST_GeomFromText('POINT (-48.23456 20.12345)'))", "<gml:Point>\n" + " <gml:coordinates>\n" + " -48.23456,20.12345 \n" + " </gml:coordinates>\n" + "</gml:Point>\n" ); assertEval( "ST_AsGML(ST_GeomFromText('POLYGON ((40 0, 50 50, 0 50, 0 0, 40 0))', 4326))", "<gml:Polygon srsName='EPSG:4326'>\n" + " <gml:outerBoundaryIs>\n" + " <gml:LinearRing>\n" + " <gml:coordinates>\n" + " 40.0,0.0 50.0,50.0 0.0,50.0 0.0,0.0 40.0,0.0 \n" + " </gml:coordinates>\n" + " </gml:LinearRing>\n" + " </gml:outerBoundaryIs>\n" + "</gml:Polygon>\n" ); }
@Test public void testResolveCoalesce4() throws Exception { String sql = "coalesce({d'2009-03-11'}, 1)"; //$NON-NLS-1$ helpResolveFunction(sql); }
@Test(expected=TeiidRuntimeException.class) public void testLongTimestampAddLiteral() throws Exception { org.teiid.query.sql.symbol.Expression ex = TestFunctionResolving.getExpression("timestampadd(sql_tsi_second, 9999999999, now())"); TstLanguageBridgeFactory.factory.translate(ex); }
@Test public void testFromGml() throws Exception { assertEval( "ST_AsText(ST_GeomFromGML('" + "<gml:Point>\n" + " <gml:coordinates>\n" + " -48.23456,20.12345 \n" + " </gml:coordinates>\n" + "</gml:Point>'))", "POINT (-48.23456 20.12345)" ); assertEval("ST_AsText(ST_GeomFromGML('" + "<gml:Polygon>\n" + " <gml:outerBoundaryIs>\n" + " <gml:LinearRing>\n" + " <gml:coordinates>\n" + " 40.0,0.0 50.0,50.0 0.0,50.0 0.0,0.0 40.0,0.0 \n" + " </gml:coordinates>\n" + " </gml:LinearRing>\n" + " </gml:outerBoundaryIs>\n" + "</gml:Polygon>'))", "POLYGON ((40 0, 50 50, 0 50, 0 0, 40 0))" ); }