aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/main/scala/org/apache/spark/sql/execution/Queryable.scala
diff options
context:
space:
mode:
Diffstat (limited to 'sql/core/src/main/scala/org/apache/spark/sql/execution/Queryable.scala')
-rw-r--r--sql/core/src/main/scala/org/apache/spark/sql/execution/Queryable.scala124
1 files changed, 0 insertions, 124 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/Queryable.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/Queryable.scala
deleted file mode 100644
index 38263af0f7..0000000000
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/Queryable.scala
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.spark.sql.execution
-
-import scala.util.control.NonFatal
-
-import org.apache.commons.lang3.StringUtils
-
-import org.apache.spark.sql.SQLContext
-import org.apache.spark.sql.types.StructType
-
-/** A trait that holds shared code between DataFrames and Datasets. */
-private[sql] trait Queryable {
- def schema: StructType
- def queryExecution: QueryExecution
- def sqlContext: SQLContext
-
- override def toString: String = {
- try {
- val builder = new StringBuilder
- val fields = schema.take(2).map {
- case f => s"${f.name}: ${f.dataType.simpleString(2)}"
- }
- builder.append("[")
- builder.append(fields.mkString(", "))
- if (schema.length > 2) {
- if (schema.length - fields.size == 1) {
- builder.append(" ... 1 more field")
- } else {
- builder.append(" ... " + (schema.length - 2) + " more fields")
- }
- }
- builder.append("]").toString()
- } catch {
- case NonFatal(e) =>
- s"Invalid tree; ${e.getMessage}:\n$queryExecution"
- }
- }
-
- def printSchema(): Unit
-
- def explain(extended: Boolean): Unit
-
- def explain(): Unit
-
- private[sql] def showString(_numRows: Int, truncate: Boolean = true): String
-
- /**
- * Format the string representing rows for output
- * @param rows The rows to show
- * @param numRows Number of rows to show
- * @param hasMoreData Whether some rows are not shown due to the limit
- * @param truncate Whether truncate long strings and align cells right
- *
- */
- private[sql] def formatString (
- rows: Seq[Seq[String]],
- numRows: Int,
- hasMoreData : Boolean,
- truncate: Boolean = true): String = {
- val sb = new StringBuilder
- val numCols = schema.fieldNames.length
-
- // Initialise the width of each column to a minimum value of '3'
- val colWidths = Array.fill(numCols)(3)
-
- // Compute the width of each column
- for (row <- rows) {
- for ((cell, i) <- row.zipWithIndex) {
- colWidths(i) = math.max(colWidths(i), cell.length)
- }
- }
-
- // Create SeparateLine
- val sep: String = colWidths.map("-" * _).addString(sb, "+", "+", "+\n").toString()
-
- // column names
- rows.head.zipWithIndex.map { case (cell, i) =>
- if (truncate) {
- StringUtils.leftPad(cell, colWidths(i))
- } else {
- StringUtils.rightPad(cell, colWidths(i))
- }
- }.addString(sb, "|", "|", "|\n")
-
- sb.append(sep)
-
- // data
- rows.tail.map {
- _.zipWithIndex.map { case (cell, i) =>
- if (truncate) {
- StringUtils.leftPad(cell.toString, colWidths(i))
- } else {
- StringUtils.rightPad(cell.toString, colWidths(i))
- }
- }.addString(sb, "|", "|", "|\n")
- }
-
- sb.append(sep)
-
- // For Data that has more than "numRows" records
- if (hasMoreData) {
- val rowsString = if (numRows == 1) "row" else "rows"
- sb.append(s"only showing top $numRows $rowsString\n")
- }
-
- sb.toString()
- }
-}