@Override public String getPath() { return session.getPath().toString(); }
@Override public String toString() { if (rawPath.isPresent()) { return Joiner.on(", ").join(getParsedPath()); } //empty string is only used for an uninitialized path, as an empty path would be \"\" return ""; } }
public List<SqlPathElement> getParsedPath() { if (parsedPath == null) { parsePath(); } return parsedPath; }
SqlPath sqlPath = new SqlPath(Optional.of(statement.getPathSpecification().toString())); for (SqlPathElement element : sqlPath.getParsedPath()) { if (!element.getCatalog().isPresent() && !session.getCatalog().isPresent()) { throw new SemanticException(CATALOG_NOT_SPECIFIED, statement, "Catalog must be specified for each path element when session catalog is not set"); stateMachine.setSetPath(sqlPath.toString()); return immediateFuture(null);
@Test public void testCurrentPath() { Session session = testSessionBuilder() .setPath(new SqlPath(Optional.of("testPath"))) .build(); try (QueryAssertions queryAssertions = new QueryAssertions(session)) { queryAssertions.assertQuery("SELECT CURRENT_PATH", "SELECT CAST('" + session.getPath().toString() + "' AS VARCHAR)"); } Session emptyPathSession = testSessionBuilder() .setPath(new SqlPath(Optional.of("\"\""))) .build(); try (QueryAssertions queryAssertions = new QueryAssertions(emptyPathSession)) { queryAssertions.assertQuery("SELECT CURRENT_PATH", "SELECT CAST('" + emptyPathSession.getPath().toString() + "' AS VARCHAR)"); } } }
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "\\Qline 1:9: mismatched input '.'. Expecting: ',', <EOF>\\E") public void testInvalidPath() { SqlEnvironmentConfig config = new SqlEnvironmentConfig().setPath("too.many.qualifiers"); new SqlPath(config.getPath()).getParsedPath(); } }
public static SessionBuilder testSessionBuilder(SessionPropertyManager sessionPropertyManager) { return Session.builder(sessionPropertyManager) .setQueryId(queryIdGenerator.createNextQueryId()) .setIdentity(new Identity("user", Optional.empty())) .setSource("test") .setCatalog("catalog") .setSchema("schema") .setPath(new SqlPath(Optional.of("path"))) .setTimeZoneKey(DEFAULT_TIME_ZONE_KEY) .setLocale(ENGLISH) .setRemoteUserAddress("address") .setUserAgent("agent"); }
assertEquals(session.getCatalog().get(), "testCatalog"); assertEquals(session.getSchema().get(), "testSchema"); assertEquals(session.getPath().getRawPath().get(), "testPath"); assertEquals(session.getLocale(), Locale.TAIWAN); assertEquals(session.getTimeZoneKey(), getTimeZoneKey("Asia/Taipei"));
SqlPath sqlPath = new SqlPath(Optional.of(statement.getPathSpecification().toString())); for (SqlPathElement element : sqlPath.getParsedPath()) { if (!element.getCatalog().isPresent() && !session.getCatalog().isPresent()) { throw new SemanticException(CATALOG_NOT_SPECIFIED, statement, "Catalog must be specified for each path element when session catalog is not set"); stateMachine.setSetPath(sqlPath.toString()); return immediateFuture(null);
@Test public void testCurrentPath() { Session session = testSessionBuilder() .setPath(new SqlPath(Optional.of("testPath"))) .build(); try (QueryAssertions queryAssertions = new QueryAssertions(session)) { queryAssertions.assertQuery("SELECT CURRENT_PATH", "SELECT CAST('" + session.getPath().toString() + "' AS VARCHAR)"); } Session emptyPathSession = testSessionBuilder() .setPath(new SqlPath(Optional.of("\"\""))) .build(); try (QueryAssertions queryAssertions = new QueryAssertions(emptyPathSession)) { queryAssertions.assertQuery("SELECT CURRENT_PATH", "SELECT CAST('" + emptyPathSession.getPath().toString() + "' AS VARCHAR)"); } } }
@Test(expectedExceptions = ParsingException.class, expectedExceptionsMessageRegExp = "\\Qline 1:9: mismatched input '.'. Expecting: ',', <EOF>\\E") public void testInvalidPath() { SqlEnvironmentConfig config = new SqlEnvironmentConfig().setPath("too.many.qualifiers"); new SqlPath(config.getPath()).getParsedPath(); } }
public static SessionBuilder testSessionBuilder(SessionPropertyManager sessionPropertyManager) { return Session.builder(sessionPropertyManager) .setQueryId(queryIdGenerator.createNextQueryId()) .setIdentity(new Identity("user", Optional.empty())) .setSource("test") .setCatalog("catalog") .setSchema("schema") .setPath(new SqlPath(Optional.of("path"))) .setTimeZoneKey(DEFAULT_TIME_ZONE_KEY) .setLocale(ENGLISH) .setRemoteUserAddress("address") .setUserAgent("agent"); }
assertEquals(session.getCatalog().get(), "testCatalog"); assertEquals(session.getSchema().get(), "testSchema"); assertEquals(session.getPath().getRawPath().get(), "testPath"); assertEquals(session.getLocale(), Locale.TAIWAN); assertEquals(session.getTimeZoneKey(), getTimeZoneKey("Asia/Taipei"));
@Test public void testSqlPathCreation() { ImmutableList.Builder<SqlPathElement> correctValues = ImmutableList.builder(); correctValues.add(new SqlPathElement( Optional.of(new Identifier("normal")), new Identifier("schema"))); correctValues.add(new SqlPathElement( Optional.of(new Identifier("who.uses.periods")), new Identifier("in.schema.names"))); correctValues.add(new SqlPathElement( Optional.of(new Identifier("same,deal")), new Identifier("with,commas"))); correctValues.add(new SqlPathElement( Optional.of(new Identifier("aterrible")), new Identifier("thing!@#$%^&*()"))); List<SqlPathElement> expected = correctValues.build(); SqlPath path = new SqlPath(Optional.of("normal.schema," + "\"who.uses.periods\".\"in.schema.names\"," + "\"same,deal\".\"with,commas\"," + "aterrible.\"thing!@#$%^&*()\"")); assertEquals(path.getParsedPath(), expected); assertEquals(path.toString(), Joiner.on(", ").join(expected)); } }
session.getCatalog().orElse(null), session.getSchema().orElse(null), session.getPath().toString(), ZoneId.of(session.getTimeZoneKey().getId()), session.getLocale(),
@Override public String toString() { if (rawPath.isPresent()) { return Joiner.on(", ").join(getParsedPath()); } //empty string is only used for an uninitialized path, as an empty path would be \"\" return ""; } }
public List<SqlPathElement> getParsedPath() { if (parsedPath == null) { parsePath(); } return parsedPath; }
@Test public void testSqlPathCreation() { ImmutableList.Builder<SqlPathElement> correctValues = ImmutableList.builder(); correctValues.add(new SqlPathElement( Optional.of(new Identifier("normal")), new Identifier("schema"))); correctValues.add(new SqlPathElement( Optional.of(new Identifier("who.uses.periods")), new Identifier("in.schema.names"))); correctValues.add(new SqlPathElement( Optional.of(new Identifier("same,deal")), new Identifier("with,commas"))); correctValues.add(new SqlPathElement( Optional.of(new Identifier("aterrible")), new Identifier("thing!@#$%^&*()"))); List<SqlPathElement> expected = correctValues.build(); SqlPath path = new SqlPath(Optional.of("normal.schema," + "\"who.uses.periods\".\"in.schema.names\"," + "\"same,deal\".\"with,commas\"," + "aterrible.\"thing!@#$%^&*()\"")); assertEquals(path.getParsedPath(), expected); assertEquals(path.toString(), Joiner.on(", ").join(expected)); } }
@ScalarFunction(value = "$current_path", hidden = true) @Description("retrieve current path") @SqlType(StandardTypes.VARCHAR) public static Slice currentPath(ConnectorSession session) { // this function is a language construct and has special access to internals return utf8Slice(((FullConnectorSession) session).getSession().getPath().toString()); } }