|
17 | 17 |
|
18 | 18 | package org.apache.kyuubi.engine.flink.operation
|
19 | 19 |
|
| 20 | +import java.util |
20 | 21 | import java.util.concurrent.{RejectedExecutionException, ScheduledExecutorService, TimeUnit}
|
21 | 22 |
|
22 | 23 | import scala.collection.JavaConverters._
|
23 | 24 | import scala.collection.mutable.ArrayBuffer
|
24 | 25 |
|
25 | 26 | import com.google.common.annotations.VisibleForTesting
|
26 |
| -import org.apache.flink.table.api.ResultKind |
| 27 | +import org.apache.flink.table.api.{DataTypes, ResultKind} |
| 28 | +import org.apache.flink.table.catalog.Column |
27 | 29 | import org.apache.flink.table.client.gateway.{Executor, TypedResult}
|
28 | 30 | import org.apache.flink.table.operations.{Operation, QueryOperation}
|
| 31 | +import org.apache.flink.table.operations.command.{ResetOperation, SetOperation} |
29 | 32 | import org.apache.flink.types.Row
|
30 | 33 |
|
31 | 34 | import org.apache.kyuubi.{KyuubiSQLException, Logging}
|
32 |
| -import org.apache.kyuubi.engine.flink.result.ResultSet |
| 35 | +import org.apache.kyuubi.engine.flink.result.{OperationUtil, ResultSet} |
33 | 36 | import org.apache.kyuubi.operation.{OperationState, OperationType}
|
34 | 37 | import org.apache.kyuubi.operation.log.OperationLog
|
35 | 38 | import org.apache.kyuubi.session.Session
|
@@ -100,6 +103,8 @@ class ExecuteStatement(
|
100 | 103 | val operation = executor.parseStatement(sessionId, statement)
|
101 | 104 | operation match {
|
102 | 105 | case queryOperation: QueryOperation => runQueryOperation(queryOperation)
|
| 106 | + case setOperation: SetOperation => runSetOperation(setOperation) |
| 107 | + case resetOperation: ResetOperation => runResetOperation(resetOperation) |
103 | 108 | case operation: Operation => runOperation(operation)
|
104 | 109 | }
|
105 | 110 | } catch {
|
@@ -139,6 +144,64 @@ class ExecuteStatement(
|
139 | 144 | setState(OperationState.FINISHED)
|
140 | 145 | }
|
141 | 146 |
|
| 147 | + private def runSetOperation(setOperation: SetOperation): Unit = { |
| 148 | + if (setOperation.getKey.isPresent) { |
| 149 | + val key: String = setOperation.getKey.get.trim |
| 150 | + |
| 151 | + if (setOperation.getValue.isPresent) { |
| 152 | + val newValue: String = setOperation.getValue.get.trim |
| 153 | + executor.setSessionProperty(sessionId, key, newValue) |
| 154 | + } |
| 155 | + |
| 156 | + val value = executor.getSessionConfigMap(sessionId).getOrDefault(key, "") |
| 157 | + resultSet = ResultSet.builder |
| 158 | + .resultKind(ResultKind.SUCCESS_WITH_CONTENT) |
| 159 | + .columns( |
| 160 | + Column.physical("key", DataTypes.STRING()), |
| 161 | + Column.physical("value", DataTypes.STRING())) |
| 162 | + .data(Array(Row.of(key, value))) |
| 163 | + .build |
| 164 | + } else { |
| 165 | + // show all properties if set without key |
| 166 | + val properties: util.Map[String, String] = executor.getSessionConfigMap(sessionId) |
| 167 | + |
| 168 | + val entries = ArrayBuffer.empty[Row] |
| 169 | + properties.forEach((key, value) => entries.append(Row.of(key, value))) |
| 170 | + |
| 171 | + if (entries.nonEmpty) { |
| 172 | + val prettyEntries = entries.sortBy(_.getField(0).asInstanceOf[String]) |
| 173 | + resultSet = ResultSet.builder |
| 174 | + .resultKind(ResultKind.SUCCESS_WITH_CONTENT) |
| 175 | + .columns( |
| 176 | + Column.physical("key", DataTypes.STRING()), |
| 177 | + Column.physical("value", DataTypes.STRING())) |
| 178 | + .data(prettyEntries.toArray) |
| 179 | + .build |
| 180 | + } else { |
| 181 | + resultSet = ResultSet.builder |
| 182 | + .resultKind(ResultKind.SUCCESS_WITH_CONTENT) |
| 183 | + .columns( |
| 184 | + Column.physical("key", DataTypes.STRING()), |
| 185 | + Column.physical("value", DataTypes.STRING())) |
| 186 | + .data(Array[Row]()) |
| 187 | + .build |
| 188 | + } |
| 189 | + } |
| 190 | + setState(OperationState.FINISHED) |
| 191 | + } |
| 192 | + |
| 193 | + private def runResetOperation(resetOperation: ResetOperation): Unit = { |
| 194 | + if (resetOperation.getKey.isPresent) { |
| 195 | + // reset the given property |
| 196 | + executor.resetSessionProperty(sessionId, resetOperation.getKey.get()) |
| 197 | + } else { |
| 198 | + // reset all properties |
| 199 | + executor.resetSessionProperties(sessionId) |
| 200 | + } |
| 201 | + resultSet = OperationUtil.successResultSet() |
| 202 | + setState(OperationState.FINISHED) |
| 203 | + } |
| 204 | + |
142 | 205 | private def runOperation(operation: Operation): Unit = {
|
143 | 206 | val result = executor.executeOperation(sessionId, operation)
|
144 | 207 | result.await()
|
|
0 commit comments