Skip to content

Commit

Permalink
move more to non-static
Browse files Browse the repository at this point in the history
  • Loading branch information
kgyrtkirk committed Jul 30, 2024
1 parent f6cc540 commit 78b75d3
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.druid.sql.calcite.schema.NamedViewSchema;
import org.apache.druid.sql.calcite.schema.ViewSchema;
import org.apache.druid.sql.calcite.util.CalciteTests;
import org.apache.druid.sql.hook.DruidHookDispatcher;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -75,7 +76,8 @@ NamedViewSchema.NAME, new NamedViewSchema(EasyMock.createMock(ViewSchema.class))
"druid",
new CalciteRulesManager(ImmutableSet.of()),
CalciteTests.TEST_AUTHORIZER_MAPPER,
AuthConfig.newBuilder().build()
AuthConfig.newBuilder().build(),
new DruidHookDispatcher()
);
final NativeSqlEngine engine = CalciteTests.createMockSqlEngine(
EasyMock.createMock(QuerySegmentWalker.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.apache.druid.sql.calcite.run.EngineFeature;
import org.apache.druid.sql.calcite.run.QueryMaker;
import org.apache.druid.sql.calcite.run.SqlEngine;
import org.apache.druid.sql.hook.DruidHook.HookKey;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Interval;
Expand Down Expand Up @@ -668,4 +669,9 @@ public LookupExtractor getLookup(final String lookupName)

return lookupCache.getLookup(lookupName);
}

public <T> void dispatchHook(HookKey<T> key, T object)
{
plannerToolbox.getHookDispatcher().dispatch(key, object);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public class PlannerFactory extends PlannerToolbox
.setConformance(DruidConformance.instance())
.setParserFactory(new DruidSqlParserImplFactory()) // Custom SQL parser factory
.build();
private final DruidHookDispatcher hookDispatcher;

@Inject
public PlannerFactory(
Expand Down Expand Up @@ -95,9 +94,9 @@ public PlannerFactory(
druidSchemaName,
calciteRuleManager,
authorizerMapper,
authConfig
authConfig,
hookDispatcher
);
this.hookDispatcher = hookDispatcher;
}

/**
Expand All @@ -117,7 +116,7 @@ public DruidPlanner createPlanner(
queryContext,
hook
);
hookDispatcher.dispatch(DruidHook.SQL, sql);
context.dispatchHook(DruidHook.SQL, sql);

return new DruidPlanner(buildFrameworkConfig(context), context, engine, hook);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.druid.server.security.AuthConfig;
import org.apache.druid.server.security.AuthorizerMapper;
import org.apache.druid.sql.calcite.schema.DruidSchemaCatalog;
import org.apache.druid.sql.hook.DruidHookDispatcher;

public class PlannerToolbox
{
Expand All @@ -40,6 +41,7 @@ public class PlannerToolbox
protected final CalciteRulesManager calciteRuleManager;
protected final AuthorizerMapper authorizerMapper;
protected final AuthConfig authConfig;
protected final DruidHookDispatcher hookDispatcher;

public PlannerToolbox(
final DruidOperatorTable operatorTable,
Expand All @@ -52,7 +54,8 @@ public PlannerToolbox(
final String druidSchemaName,
final CalciteRulesManager calciteRuleManager,
final AuthorizerMapper authorizerMapper,
final AuthConfig authConfig
final AuthConfig authConfig,
final DruidHookDispatcher hookDispatcher
)
{
this.operatorTable = operatorTable;
Expand All @@ -66,6 +69,7 @@ public PlannerToolbox(
this.calciteRuleManager = calciteRuleManager;
this.authorizerMapper = authorizerMapper;
this.authConfig = authConfig;
this.hookDispatcher = hookDispatcher;
}

public DruidOperatorTable operatorTable()
Expand Down Expand Up @@ -117,4 +121,9 @@ public AuthConfig getAuthConfig()
{
return authConfig;
}

public DruidHookDispatcher getHookDispatcher()
{
return hookDispatcher;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ protected PlannerResult planWithDruidConvention() throws ValidationException
.plus(DruidLogicalConvention.instance()),
newRoot
);
DruidHook.dispatch(DruidHook.DRUID_PLAN, newRoot);

plannerContext.dispatchHook(DruidHook.DRUID_PLAN, newRoot);

DruidQueryGenerator generator = new DruidQueryGenerator(plannerContext, (DruidLogicalNode) newRoot, rexBuilder);
DruidQuery baseQuery = generator.buildQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.apache.druid.sql.calcite.table.RowSignatures;
import org.apache.druid.sql.calcite.util.CalciteTestBase;
import org.apache.druid.sql.calcite.util.CalciteTests;
import org.apache.druid.sql.hook.DruidHookDispatcher;
import org.easymock.EasyMock;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
Expand Down Expand Up @@ -97,7 +98,8 @@ NamedViewSchema.NAME, new NamedViewSchema(EasyMock.createMock(ViewSchema.class))
"druid",
new CalciteRulesManager(ImmutableSet.of()),
CalciteTests.TEST_AUTHORIZER_MAPPER,
AuthConfig.newBuilder().build()
AuthConfig.newBuilder().build(),
new DruidHookDispatcher()
);
public static final PlannerContext PLANNER_CONTEXT = PlannerContext.create(
PLANNER_TOOLBOX,
Expand Down Expand Up @@ -336,7 +338,7 @@ void testExpression(
}

ExprEval<?> result = PLANNER_CONTEXT.parseExpression(expression.getExpression())

.eval(expressionBindings);

Assert.assertEquals("Result for: " + rexNode, expectedResult, result.value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.druid.sql.calcite.schema.NamedViewSchema;
import org.apache.druid.sql.calcite.schema.ViewSchema;
import org.apache.druid.sql.calcite.util.CalciteTests;
import org.apache.druid.sql.hook.DruidHookDispatcher;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -71,7 +72,8 @@ NamedViewSchema.NAME, new NamedViewSchema(EasyMock.createMock(ViewSchema.class))
"druid",
new CalciteRulesManager(ImmutableSet.of()),
CalciteTests.TEST_AUTHORIZER_MAPPER,
AuthConfig.newBuilder().build()
AuthConfig.newBuilder().build(),
new DruidHookDispatcher()
);
final PlannerContext plannerContext = PlannerContext.create(
toolbox,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.apache.druid.sql.calcite.schema.NamedSchema;
import org.apache.druid.sql.calcite.util.CalciteTestBase;
import org.apache.druid.sql.calcite.util.CalciteTests;
import org.apache.druid.sql.hook.DruidHookDispatcher;
import org.easymock.EasyMock;
import org.easymock.EasyMockExtension;
import org.easymock.Mock;
Expand Down Expand Up @@ -192,7 +193,8 @@ public void testExtensionCalciteRule()
"druid",
new CalciteRulesManager(ImmutableSet.of()),
CalciteTests.TEST_AUTHORIZER_MAPPER,
AuthConfig.newBuilder().build()
AuthConfig.newBuilder().build(),
new DruidHookDispatcher()
);

PlannerContext context = PlannerContext.create(
Expand Down Expand Up @@ -224,7 +226,8 @@ public void testConfigurableBloat()
"druid",
new CalciteRulesManager(ImmutableSet.of()),
CalciteTests.TEST_AUTHORIZER_MAPPER,
AuthConfig.newBuilder().build()
AuthConfig.newBuilder().build(),
new DruidHookDispatcher()
);

PlannerContext contextWithBloat = PlannerContext.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.druid.sql.calcite.table.RowSignatures;
import org.apache.druid.sql.calcite.util.CalciteTestBase;
import org.apache.druid.sql.calcite.util.CalciteTests;
import org.apache.druid.sql.hook.DruidHookDispatcher;
import org.apache.druid.testing.InitializedNullHandlingTest;
import org.easymock.EasyMock;
import org.junit.Assert;
Expand Down Expand Up @@ -100,7 +101,8 @@ NamedViewSchema.NAME, new NamedViewSchema(EasyMock.createMock(ViewSchema.class))
"druid",
new CalciteRulesManager(ImmutableSet.of()),
CalciteTests.TEST_AUTHORIZER_MAPPER,
AuthConfig.newBuilder().build()
AuthConfig.newBuilder().build(),
new DruidHookDispatcher()
);
private static final PlannerContext PLANNER_CONTEXT = PlannerContext.create(
PLANNER_TOOLBOX,
Expand Down

0 comments on commit 78b75d3

Please sign in to comment.