forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
844 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
sql/core/src/main/scala/org/apache/spark/sql/json/JSONRelation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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.json | ||
|
||
import org.apache.spark.sql.{SQLConf, SQLContext} | ||
import org.apache.spark.sql.sources._ | ||
|
||
private[sql] class DefaultSource extends RelationProvider { | ||
/** Returns a new base relation with the given parameters. */ | ||
override def createRelation( | ||
sqlContext: SQLContext, | ||
parameters: Map[String, String]): BaseRelation = { | ||
val fileName = | ||
parameters.getOrElse("fileName", sys.error(s"Option 'fileName' not specified")) | ||
|
||
val samplingRatio = | ||
parameters.get("samplingRatio").map(_.toDouble).getOrElse(1.0) | ||
|
||
JSONRelation(fileName, samplingRatio)(sqlContext) | ||
} | ||
} | ||
|
||
private[sql] case class JSONRelation(fileName: String, samplingRatio: Double)( | ||
@transient val sqlContext: SQLContext) | ||
extends BaseRelation with TableScan { | ||
|
||
private def baseRDD = sqlContext.sparkContext.textFile(fileName) | ||
|
||
override val schema = | ||
JsonRDD.inferSchema( | ||
baseRDD, | ||
samplingRatio, | ||
sqlContext.columnNameOfCorruptRecord) | ||
|
||
override def buildScan() = | ||
JsonRDD.jsonStringToRow(baseRDD, schema, sqlContext.columnNameOfCorruptRecord) | ||
} |
21 changes: 21 additions & 0 deletions
21
sql/core/src/main/scala/org/apache/spark/sql/sources/DataSource.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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.sources | ||
|
||
import org.apache.spark.sql.SQLContext | ||
|
||
|
56 changes: 56 additions & 0 deletions
56
sql/core/src/main/scala/org/apache/spark/sql/sources/LogicalRelation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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.sources | ||
|
||
import org.apache.spark.sql.catalyst.analysis.MultiInstanceRelation | ||
import org.apache.spark.sql.catalyst.expressions.{AttributeMap, Expression, Attribute} | ||
import org.apache.spark.sql.catalyst.plans.logical.{Statistics, LogicalPlan} | ||
import org.apache.spark.sql.catalyst.trees.LeafNode | ||
|
||
/** | ||
* Used to link a [[BaseRelation]] in to a logical query plan. | ||
*/ | ||
private[sql] case class LogicalRelation(relation: BaseRelation) | ||
extends LogicalPlan | ||
with LeafNode[LogicalPlan] | ||
with MultiInstanceRelation { | ||
|
||
val output = relation.schema.toAttributes | ||
|
||
// Logical Relations are distinct if they have different output for the sake of transformations. | ||
override def equals(other: Any) = other match { | ||
case l @ LogicalRelation(otherRelation) => relation == otherRelation && output == l.output | ||
case _ => false | ||
} | ||
|
||
override def sameResult(otherPlan: LogicalPlan) = otherPlan match { | ||
case LogicalRelation(otherRelation) => relation == otherRelation | ||
case _ => false | ||
} | ||
|
||
@transient override lazy val statistics = Statistics( | ||
// TODO: Allow datasources to provide statistics as well. | ||
sizeInBytes = BigInt(relation.sqlContext.defaultSizeInBytes) | ||
) | ||
|
||
/** Used to lookup original attribute capitalization */ | ||
val attributeMap = AttributeMap(output.map(o => (o, o))) | ||
|
||
def newInstance() = LogicalRelation(relation).asInstanceOf[this.type] | ||
|
||
override def simpleString = s"Relation[${output.mkString(",")}] $relation" | ||
} |
Oops, something went wrong.