SqlPath sqlPath = new SqlPath(Optional.of(statement.getPathSpecification().toString()));
SqlPath sqlPath = new SqlPath(Optional.of(statement.getPathSpecification().toString()));
@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(); } }
@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"); }
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"); }
@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)); } }
@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)); } }
@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 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)"); } } }
.setQueryId(queryId) .setIdentity(sessionContext.getIdentity()) .setPath(new SqlPath(Optional.empty())) .build();
.setQueryId(queryId) .setIdentity(sessionContext.getIdentity()) .setPath(new SqlPath(Optional.empty())) .build();
public static Session toSession(ConnectorTransactionHandle transactionHandle, ConnectorSession session) { TransactionId transactionId = ((GlobalSystemTransactionHandle) transactionHandle).getTransactionId(); ConnectorIdentity connectorIdentity = session.getIdentity(); Identity identity = new Identity(connectorIdentity.getUser(), connectorIdentity.getPrincipal()); return Session.builder(new SessionPropertyManager(SYSTEM_SESSION_PROPERTIES)) .setQueryId(new QueryId(session.getQueryId())) .setTransactionId(transactionId) .setCatalog("catalog") .setSchema("schema") .setPath(new SqlPath(Optional.of("path"))) .setIdentity(identity) .setTimeZoneKey(session.getTimeZoneKey()) .setLocale(session.getLocale()) .setStartTime(session.getStartTime()) .build(); } }
public static Session toSession(ConnectorTransactionHandle transactionHandle, ConnectorSession session) { TransactionId transactionId = ((GlobalSystemTransactionHandle) transactionHandle).getTransactionId(); ConnectorIdentity connectorIdentity = session.getIdentity(); Identity identity = new Identity(connectorIdentity.getUser(), connectorIdentity.getPrincipal()); return Session.builder(new SessionPropertyManager(SYSTEM_SESSION_PROPERTIES)) .setQueryId(new QueryId(session.getQueryId())) .setTransactionId(transactionId) .setCatalog("catalog") .setSchema("schema") .setPath(new SqlPath(Optional.of("path"))) .setIdentity(identity) .setTimeZoneKey(session.getTimeZoneKey()) .setLocale(session.getLocale()) .setStartTime(session.getStartTime()) .build(); } }