|
15 | 15 |
|
16 | 16 | import com.facebook.presto.common.RuntimeStats;
|
17 | 17 | import com.facebook.presto.common.function.SqlFunctionProperties;
|
| 18 | +import com.facebook.presto.common.resourceGroups.QueryType; |
18 | 19 | import com.facebook.presto.common.transaction.TransactionId;
|
19 | 20 | import com.facebook.presto.common.type.TimeZoneKey;
|
20 | 21 | import com.facebook.presto.cost.PlanCostEstimate;
|
@@ -99,6 +100,7 @@ public final class Session
|
99 | 100 | private final Optional<Tracer> tracer;
|
100 | 101 | private final WarningCollector warningCollector;
|
101 | 102 | private final RuntimeStats runtimeStats;
|
| 103 | + private final Optional<QueryType> queryType; |
102 | 104 |
|
103 | 105 | private final OptimizerInformationCollector optimizerInformationCollector = new OptimizerInformationCollector();
|
104 | 106 | private final OptimizerResultCollector optimizerResultCollector = new OptimizerResultCollector();
|
@@ -131,7 +133,8 @@ public Session(
|
131 | 133 | Map<SqlFunctionId, SqlInvokedFunction> sessionFunctions,
|
132 | 134 | Optional<Tracer> tracer,
|
133 | 135 | WarningCollector warningCollector,
|
134 |
| - RuntimeStats runtimeStats) |
| 136 | + RuntimeStats runtimeStats, |
| 137 | + Optional<QueryType> queryType) |
135 | 138 | {
|
136 | 139 | this.queryId = requireNonNull(queryId, "queryId is null");
|
137 | 140 | this.transactionId = requireNonNull(transactionId, "transactionId is null");
|
@@ -172,7 +175,8 @@ public Session(
|
172 | 175 | this.tracer = requireNonNull(tracer, "tracer is null");
|
173 | 176 | this.warningCollector = requireNonNull(warningCollector, "warningCollector is null");
|
174 | 177 | this.runtimeStats = requireNonNull(runtimeStats, "runtimeStats is null");
|
175 |
| - this.context = new AccessControlContext(queryId, clientInfo, clientTags, source, warningCollector, runtimeStats); |
| 178 | + this.queryType = requireNonNull(queryType, "queryType is null"); |
| 179 | + this.context = new AccessControlContext(queryId, clientInfo, clientTags, source, warningCollector, runtimeStats, queryType); |
176 | 180 | }
|
177 | 181 |
|
178 | 182 | public QueryId getQueryId()
|
@@ -353,6 +357,11 @@ public Map<PlanNodeId, PlanCostEstimate> getPlanNodeCostMap()
|
353 | 357 | return planNodeCostMap;
|
354 | 358 | }
|
355 | 359 |
|
| 360 | + public Optional<QueryType> getQueryType() |
| 361 | + { |
| 362 | + return queryType; |
| 363 | + } |
| 364 | + |
356 | 365 | public Session beginTransactionId(TransactionId transactionId, TransactionManager transactionManager, AccessControl accessControl)
|
357 | 366 | {
|
358 | 367 | requireNonNull(transactionId, "transactionId is null");
|
@@ -447,63 +456,8 @@ public Session beginTransactionId(TransactionId transactionId, TransactionManage
|
447 | 456 | sessionFunctions,
|
448 | 457 | tracer,
|
449 | 458 | warningCollector,
|
450 |
| - runtimeStats); |
451 |
| - } |
452 |
| - |
453 |
| - public Session withDefaultProperties( |
454 |
| - SystemSessionPropertyConfiguration systemPropertyConfiguration, |
455 |
| - Map<String, Map<String, String>> catalogPropertyDefaults) |
456 |
| - { |
457 |
| - requireNonNull(systemPropertyConfiguration, "systemPropertyConfiguration is null"); |
458 |
| - requireNonNull(catalogPropertyDefaults, "catalogPropertyDefaults is null"); |
459 |
| - |
460 |
| - // to remove this check properties must be authenticated and validated as in beginTransactionId |
461 |
| - checkState( |
462 |
| - !this.transactionId.isPresent() && this.connectorProperties.isEmpty(), |
463 |
| - "Session properties cannot be overridden once a transaction is active"); |
464 |
| - |
465 |
| - Map<String, String> systemProperties = new HashMap<>(); |
466 |
| - systemProperties.putAll(systemPropertyConfiguration.systemPropertyDefaults); |
467 |
| - systemProperties.putAll(this.systemProperties); |
468 |
| - systemProperties.putAll(systemPropertyConfiguration.systemPropertyOverrides); |
469 |
| - |
470 |
| - Map<String, Map<String, String>> connectorProperties = catalogPropertyDefaults.entrySet().stream() |
471 |
| - .map(entry -> Maps.immutableEntry(entry.getKey(), new HashMap<>(entry.getValue()))) |
472 |
| - .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); |
473 |
| - for (Entry<String, Map<String, String>> catalogProperties : this.unprocessedCatalogProperties.entrySet()) { |
474 |
| - String catalog = catalogProperties.getKey(); |
475 |
| - for (Entry<String, String> entry : catalogProperties.getValue().entrySet()) { |
476 |
| - connectorProperties.computeIfAbsent(catalog, id -> new HashMap<>()) |
477 |
| - .put(entry.getKey(), entry.getValue()); |
478 |
| - } |
479 |
| - } |
480 |
| - |
481 |
| - return new Session( |
482 |
| - queryId, |
483 |
| - transactionId, |
484 |
| - clientTransactionSupport, |
485 |
| - identity, |
486 |
| - source, |
487 |
| - catalog, |
488 |
| - schema, |
489 |
| - traceToken, |
490 |
| - timeZoneKey, |
491 |
| - locale, |
492 |
| - remoteUserAddress, |
493 |
| - userAgent, |
494 |
| - clientInfo, |
495 |
| - clientTags, |
496 |
| - resourceEstimates, |
497 |
| - startTime, |
498 |
| - systemProperties, |
499 |
| - ImmutableMap.of(), |
500 |
| - connectorProperties, |
501 |
| - sessionPropertyManager, |
502 |
| - preparedStatements, |
503 |
| - sessionFunctions, |
504 |
| - tracer, |
505 |
| - warningCollector, |
506 |
| - runtimeStats); |
| 459 | + runtimeStats, |
| 460 | + queryType); |
507 | 461 | }
|
508 | 462 |
|
509 | 463 | public ConnectorSession toConnectorSession()
|
@@ -630,6 +584,7 @@ public static class SessionBuilder
|
630 | 584 | private final SessionPropertyManager sessionPropertyManager;
|
631 | 585 | private final Map<String, String> preparedStatements = new HashMap<>();
|
632 | 586 | private final Map<SqlFunctionId, SqlInvokedFunction> sessionFunctions = new HashMap<>();
|
| 587 | + private Optional<QueryType> queryType = Optional.empty(); |
633 | 588 | private WarningCollector warningCollector = WarningCollector.NOOP;
|
634 | 589 | private RuntimeStats runtimeStats = new RuntimeStats();
|
635 | 590 |
|
@@ -665,6 +620,7 @@ private SessionBuilder(Session session)
|
665 | 620 | this.tracer = requireNonNull(session.tracer, "tracer is null");
|
666 | 621 | this.warningCollector = requireNonNull(session.warningCollector, "warningCollector is null");
|
667 | 622 | this.runtimeStats = requireNonNull(session.runtimeStats, "runtimeStats is null");
|
| 623 | + this.queryType = requireNonNull(session.queryType, "queryType is null"); |
668 | 624 | }
|
669 | 625 |
|
670 | 626 | public SessionBuilder setQueryId(QueryId queryId)
|
@@ -821,11 +777,57 @@ public SessionBuilder setRuntimeStats(RuntimeStats runtimeStats)
|
821 | 777 | return this;
|
822 | 778 | }
|
823 | 779 |
|
| 780 | + public SessionBuilder setQueryType(Optional<QueryType> queryType) |
| 781 | + { |
| 782 | + this.queryType = requireNonNull(queryType, "queryType is null"); |
| 783 | + return this; |
| 784 | + } |
| 785 | + |
824 | 786 | public <T> T getSystemProperty(String name, Class<T> type)
|
825 | 787 | {
|
826 | 788 | return sessionPropertyManager.decodeSystemPropertyValue(name, systemProperties.get(name), type);
|
827 | 789 | }
|
828 | 790 |
|
| 791 | + public WarningCollector getWarningCollector() |
| 792 | + { |
| 793 | + return this.warningCollector; |
| 794 | + } |
| 795 | + |
| 796 | + public Map<String, String> getPreparedStatements() |
| 797 | + { |
| 798 | + return this.preparedStatements; |
| 799 | + } |
| 800 | + |
| 801 | + public Identity getIdentity() |
| 802 | + { |
| 803 | + return this.identity; |
| 804 | + } |
| 805 | + |
| 806 | + public Optional<String> getSource() |
| 807 | + { |
| 808 | + return Optional.ofNullable(this.source); |
| 809 | + } |
| 810 | + |
| 811 | + public Set<String> getClientTags() |
| 812 | + { |
| 813 | + return this.clientTags; |
| 814 | + } |
| 815 | + |
| 816 | + public Optional<String> getClientInfo() |
| 817 | + { |
| 818 | + return Optional.ofNullable(this.clientInfo); |
| 819 | + } |
| 820 | + |
| 821 | + public Map<String, String> getSystemProperties() |
| 822 | + { |
| 823 | + return this.systemProperties; |
| 824 | + } |
| 825 | + |
| 826 | + public Map<String, Map<String, String>> getUnprocessedCatalogProperties() |
| 827 | + { |
| 828 | + return this.catalogSessionProperties; |
| 829 | + } |
| 830 | + |
829 | 831 | public Session build()
|
830 | 832 | {
|
831 | 833 | return new Session(
|
@@ -853,7 +855,42 @@ public Session build()
|
853 | 855 | sessionFunctions,
|
854 | 856 | tracer,
|
855 | 857 | warningCollector,
|
856 |
| - runtimeStats); |
| 858 | + runtimeStats, |
| 859 | + queryType); |
| 860 | + } |
| 861 | + |
| 862 | + public void applyDefaultProperties(SystemSessionPropertyConfiguration systemPropertyConfiguration, Map<String, Map<String, String>> catalogPropertyDefaults) |
| 863 | + { |
| 864 | + requireNonNull(systemPropertyConfiguration, "systemPropertyConfiguration is null"); |
| 865 | + requireNonNull(catalogPropertyDefaults, "catalogPropertyDefaults is null"); |
| 866 | + |
| 867 | + // to remove this check properties must be authenticated and validated as in beginTransactionId |
| 868 | + checkState( |
| 869 | + this.transactionId == null && this.connectorProperties.isEmpty(), |
| 870 | + "Session properties cannot be overridden once a transaction is active"); |
| 871 | + |
| 872 | + Map<String, String> systemProperties = new HashMap<>(); |
| 873 | + systemProperties.putAll(systemPropertyConfiguration.systemPropertyDefaults); |
| 874 | + systemProperties.putAll(this.systemProperties); |
| 875 | + systemProperties.putAll(systemPropertyConfiguration.systemPropertyOverrides); |
| 876 | + this.systemProperties.putAll(systemProperties); |
| 877 | + |
| 878 | + Map<String, Map<String, String>> connectorProperties = catalogPropertyDefaults.entrySet().stream() |
| 879 | + .map(entry -> Maps.immutableEntry(entry.getKey(), new HashMap<>(entry.getValue()))) |
| 880 | + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); |
| 881 | + for (Entry<String, Map<String, String>> catalogProperties : this.catalogSessionProperties.entrySet()) { |
| 882 | + String catalog = catalogProperties.getKey(); |
| 883 | + for (Entry<String, String> entry : catalogProperties.getValue().entrySet()) { |
| 884 | + connectorProperties.computeIfAbsent(catalog, id -> new HashMap<>()).put(entry.getKey(), entry.getValue()); |
| 885 | + } |
| 886 | + } |
| 887 | + |
| 888 | + for (Entry<String, Map<String, String>> catalogProperties : connectorProperties.entrySet()) { |
| 889 | + String catalog = catalogProperties.getKey(); |
| 890 | + for (Entry<String, String> entry : catalogProperties.getValue().entrySet()) { |
| 891 | + setCatalogSessionProperty(catalog, entry.getKey(), entry.getValue()); |
| 892 | + } |
| 893 | + } |
857 | 894 | }
|
858 | 895 | }
|
859 | 896 |
|
|
0 commit comments