Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple function repository and DSL from IoC container for use anywhere #1045

Conversation

dai-chen
Copy link
Collaborator

@dai-chen dai-chen commented Nov 8, 2022

Description

!!!NOTE!!! Please ignore most file changes as they're all changing instance method to static method call on DSL. The only change matters is in FunctionRepository which becomes a singleton after this.

Problem Statement

The performance issue is improved in #944, this PR is focused on the functionality and our own DSL language adoption problem.

Currently, FunctionRepository is managed by Spring container and inject to class who needs it. DSL depends on the function repository to resolve function signature as well. This causes the function repository or DSL instance passed around and leads to "ugly" code as below:

  private final DSL dsl = new ExpressionConfig().dsl(new ExpressionConfig().functionRepository());

  dsl.equal(
    DSL.ref("integer_value", INTEGER),
    DSL.literal(integerValue(1)))),

Besides, the bigger problem is it blocks high level physical operator from building custom logic on top of the expression system. For example, the new WindowAssigner needs to calculate the lower bound of a window as below. The current coupling with Spring container make it hard to implement:

  // Assign a numeric or datetime window to the value according to its type
  Window assignWindow(ExprValue value) {
    ...
    ExprValue lowerBound = rounding.round(value);
    ExprValue windowSize = ...
    ExprValue upperBound = 
      lowerBound.isNumber()
        ? DSL.add(lowerBound, windowNumberSize)
        : DSL.adddate(lowerBound, windowIntervalSize)
  }

Solution

After double check, make FunctionRepository singleton as well as DSL. This makes both can be reused anywhere.

TODO

  1. May need to move storage engine function register code elsewhere, because it is supposed to be a static list for each storage engine. Added TODO comment for now.

Further Thoughts

  1. Will this impact storage engine register its own function in future? <= Probably not.
  2. Should basic arithmetic operation built-in ExprValue? ex. val1.add(val2) rather than DSL.add(val1, val2).valueOf(null) <= Not sure. Maybe we should.

Issues Resolved

#944

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@dai-chen dai-chen added the maintenance Improves code quality, but not the product label Nov 8, 2022
@dai-chen dai-chen added this to the Maximus M1 - Phase 1 milestone Nov 8, 2022
@dai-chen dai-chen self-assigned this Nov 8, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 8, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.72%. Comparing base (3c6b37a) to head (c45c3a4).
Report is 15 commits behind head on feature/maximus-m1.

Additional details and impacted files
@@                   Coverage Diff                    @@
##             feature/maximus-m1    #1045      +/-   ##
========================================================
- Coverage                 98.27%   95.72%   -2.55%     
  Complexity                 3423     3423              
========================================================
  Files                       342      351       +9     
  Lines                      8509     9168     +659     
  Branches                    542      661     +119     
========================================================
+ Hits                       8362     8776     +414     
- Misses                      142      334     +192     
- Partials                      5       58      +53     
Flag Coverage Δ
query-workbench 62.76% <ø> (?)
sql-engine 98.27% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dai-chen dai-chen changed the title Make function repository singleton Decouple function repository and DSL from IoC container for use anywhere Nov 8, 2022
@Yury-Fridlyand
Copy link
Collaborator

This could be conflicting with #1047.

@dai-chen
Copy link
Collaborator Author

dai-chen commented Nov 9, 2022

This could be conflicting with #1047.

Thanks for the heads up. Will review that PR tomorrow.

@dai-chen dai-chen marked this pull request as ready for review November 9, 2022 01:24
@dai-chen dai-chen requested a review from a team as a code owner November 9, 2022 01:24
Copy link
Collaborator

@penghuo penghuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the change!

Comment on lines 31 to +33
@Configuration
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {ExpressionConfig.class})
@ContextConfiguration(classes = {PhysicalPlanTestBase.class})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove these lines now (tested).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me give it a try. Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my test this is required, otherwise the following error occurred. Not sure if any new changes in 2.x or in your branch locally that I don't have?

Caused by:
        java.lang.IllegalStateException: Neither GenericXmlContextLoader nor AnnotationConfigContextLoader was able to load an ApplicationContext from [MergedContextConfiguration@1724c649 testClass = WindowOperatorTest, locations = '{}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]].
            at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:256)
            at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
            at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked out the PR as GH offers:

gh pr checkout 1045

Let me check this again.

@@ -174,5 +178,10 @@ private void validateCatalogs(List<CatalogMetadata> catalogs) {
}
}


// TODO: for now register storage engine functions here which should be static per storage engine
private void registerFunctions(String catalogName, StorageEngine storageEngine) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this method to the CatalogService interface?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why this need to be an API method of CatalogService interface? As I understand, storage-engine-defined functions are returned in StorageEngine.getFunctions() which represents additional capability of a storage engine. CatalogService can iterate static list of all storage engine (OpenSearch, Prometheus and S3 later) and register all functions internally.

@Yury-Fridlyand
Copy link
Collaborator

When I compiled code from this PR and run a simple query I got an error in stderr. Meantime, query returned a valid result.
I'm not sure that it is related to your changes, but I can't reproduce it on 2.x.

select e();
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
full
log4j:WARN Caught Exception while in Loader.getResource. This may be innocuous.
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.apache.log4j.helpers.Loader.getTCL(Loader.java:161)
    at org.apache.log4j.helpers.Loader.getResource(Loader.java:94)
    at org.apache.log4j.LogManager.<clinit>(LogManager.java:99)
    at org.apache.log4j.Logger.getLogger(Logger.java:101)
    at com.alibaba.druid.support.logging.Log4jImpl.<init>(Log4jImpl.java:41)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at com.alibaba.druid.support.logging.LogFactory.tryImplementation(LogFactory.java:63)
    at com.alibaba.druid.support.logging.LogFactory.<clinit>(LogFactory.java:29)
    at com.alibaba.druid.sql.SQLUtils.<clinit>(SQLUtils.java:62)
    at org.opensearch.sql.legacy.utils.QueryDataAnonymizer.anonymizeData(QueryDataAnonymizer.java:38)
    at org.opensearch.sql.legacy.plugin.RestSqlAction.prepareRequest(RestSqlAction.java:151)
    at org.opensearch.rest.BaseRestHandler.handleRequest(BaseRestHandler.java:102)
    at org.opensearch.rest.RestController.dispatchRequest(RestController.java:312)
    at org.opensearch.rest.RestController.tryAllHandlers(RestController.java:398)
    at org.opensearch.rest.RestController.dispatchRequest(RestController.java:241)
    at org.opensearch.http.AbstractHttpServerTransport.dispatchRequest(AbstractHttpServerTransport.java:366)
    at org.opensearch.http.AbstractHttpServerTransport.handleIncomingRequest(AbstractHttpServerTransport.java:445)
    at org.opensearch.http.AbstractHttpServerTransport.incomingRequest(AbstractHttpServerTransport.java:356)
    at org.opensearch.http.netty4.Netty4HttpRequestHandler.channelRead0(Netty4HttpRequestHandler.java:55)
    at org.opensearch.http.netty4.Netty4HttpRequestHandler.channelRead0(Netty4HttpRequestHandler.java:41)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at org.opensearch.http.netty4.Netty4HttpPipeliningHandler.channelRead(Netty4HttpPipeliningHandler.java:71)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:327)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:299)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:623)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:586)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
    at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
    at java.base/java.security.AccessController.checkPermission(AccessController.java:897)
    at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:322)
    at java.base/java.lang.ClassLoader.checkClassLoaderPermission(ClassLoader.java:2060)
    at java.base/java.lang.Thread.getContextClassLoader(Thread.java:1487)
    ... 77 more
log4j:WARN Caught Exception while in Loader.getResource. This may be innocuous.
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.apache.log4j.helpers.Loader.getTCL(Loader.java:161)
    at org.apache.log4j.helpers.Loader.getResource(Loader.java:94)
    at org.apache.log4j.LogManager.<clinit>(LogManager.java:101)
    at org.apache.log4j.Logger.getLogger(Logger.java:101)
    at com.alibaba.druid.support.logging.Log4jImpl.<init>(Log4jImpl.java:41)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at com.alibaba.druid.support.logging.LogFactory.tryImplementation(LogFactory.java:63)
    at com.alibaba.druid.support.logging.LogFactory.<clinit>(LogFactory.java:29)
    at com.alibaba.druid.sql.SQLUtils.<clinit>(SQLUtils.java:62)
    at org.opensearch.sql.legacy.utils.QueryDataAnonymizer.anonymizeData(QueryDataAnonymizer.java:38)
    at org.opensearch.sql.legacy.plugin.RestSqlAction.prepareRequest(RestSqlAction.java:151)
    at org.opensearch.rest.BaseRestHandler.handleRequest(BaseRestHandler.java:102)
    at org.opensearch.rest.RestController.dispatchRequest(RestController.java:312)
    at org.opensearch.rest.RestController.tryAllHandlers(RestController.java:398)
    at org.opensearch.rest.RestController.dispatchRequest(RestController.java:241)
    at org.opensearch.http.AbstractHttpServerTransport.dispatchRequest(AbstractHttpServerTransport.java:366)
    at org.opensearch.http.AbstractHttpServerTransport.handleIncomingRequest(AbstractHttpServerTransport.java:445)
    at org.opensearch.http.AbstractHttpServerTransport.incomingRequest(AbstractHttpServerTransport.java:356)
    at org.opensearch.http.netty4.Netty4HttpRequestHandler.channelRead0(Netty4HttpRequestHandler.java:55)
    at org.opensearch.http.netty4.Netty4HttpRequestHandler.channelRead0(Netty4HttpRequestHandler.java:41)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at org.opensearch.http.netty4.Netty4HttpPipeliningHandler.channelRead(Netty4HttpPipeliningHandler.java:71)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:327)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:299)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:623)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:586)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
    at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
    at java.base/java.security.AccessController.checkPermission(AccessController.java:897)
    at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:322)
    at java.base/java.lang.ClassLoader.checkClassLoaderPermission(ClassLoader.java:2060)
    at java.base/java.lang.Thread.getContextClassLoader(Thread.java:1487)
    ... 77 more
[bab0edff-6633-4f09-b0e4-4e019b910ac4] Incoming request /_plugins/_sql/?format=jdbc: ( SELECT e() )
[bab0edff-6633-4f09-b0e4-4e019b910ac4] Request is handled by new SQL query engine

@dai-chen
Copy link
Collaborator Author

When I compiled code from this PR and run a simple query I got an error in stderr. Meantime, query returned a valid result. I'm not sure that it is related to your changes, but I can't reproduce it on 2.x.

select e();
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")

full

Let me test from my side to confirm. Thanks!

@dai-chen
Copy link
Collaborator Author

When I compiled code from this PR and run a simple query I got an error in stderr. Meantime, query returned a valid result. I'm not sure that it is related to your changes, but I can't reproduce it on 2.x.

select e();
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")

full

The exception comes from legacy engine. I guess it's not related to this PR and curious about what happened.

    at com.alibaba.druid.sql.SQLUtils.<clinit>(SQLUtils.java:62)
    at org.opensearch.sql.legacy.utils.QueryDataAnonymizer.anonymizeData(QueryDataAnonymizer.java:38)
    at org.opensearch.sql.legacy.plugin.RestSqlAction.prepareRequest(RestSqlAction.java:151)

@Yury-Fridlyand
Copy link
Collaborator

The exception comes from legacy engine. I guess it's not related to this PR and curious about what happened.

    at com.alibaba.druid.sql.SQLUtils.<clinit>(SQLUtils.java:62)
    at org.opensearch.sql.legacy.utils.QueryDataAnonymizer.anonymizeData(QueryDataAnonymizer.java:38)
    at org.opensearch.sql.legacy.plugin.RestSqlAction.prepareRequest(RestSqlAction.java:151)

Right, but I can't reproduce it on 2.x. Can you?

@MaxKsyunz
Copy link
Collaborator

When I compiled code from this PR and run a simple query I got an error in stderr. Meantime, query returned a valid result. I'm not sure that it is related to your changes, but I can't reproduce it on 2.x.

select e();
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")

full

The exception comes from legacy engine. I guess it's not related to this PR and curious about what happened.

    at com.alibaba.druid.sql.SQLUtils.<clinit>(SQLUtils.java:62)
    at org.opensearch.sql.legacy.utils.QueryDataAnonymizer.anonymizeData(QueryDataAnonymizer.java:38)
    at org.opensearch.sql.legacy.plugin.RestSqlAction.prepareRequest(RestSqlAction.java:151)

It's coming from the anonymizer -- it uses v1 ANTLR parser to generate anonymized representation of the query. Unfortunately, the v1 ANTLR parser fails on queries that v1 engine can process.

SELECT e(); succeeds in v2, fails in v1, and anonymizer.
SELECT e() FROM calcs LIMIT 1 succeeds in v2, v1, and anonymizer. However, add a semicolon -- SELECT e() FROM calcs LIMIT 1; -- and it fails in the anonymizer.

@dai-chen
Copy link
Collaborator Author

@Yury-Fridlyand @MaxKsyunz Since feature/maximus-m1 is merged back to 2.x, let me rebase this.

@dai-chen
Copy link
Collaborator Author

dai-chen commented Nov 17, 2022

Closing as new PR #1085 based on 2.x branch is published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Improves code quality, but not the product
Development

Successfully merging this pull request may close these issues.

5 participants