-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[WIP][SQL] Incapsulate type operations #51467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.catalyst.types | ||
|
||
import org.apache.spark.sql.catalyst.expressions.Literal | ||
import org.apache.spark.sql.types.{DataType, TimeType} | ||
|
||
// Literal operations over Catalyst's types | ||
trait LiteralTypeOps { | ||
// Gets a literal with default value of the type | ||
def getDefaultLiteral: Literal | ||
} | ||
|
||
object LiteralTypeOps { | ||
def supports(dt: DataType): Boolean = dt match { | ||
case _: TimeType => true | ||
case _ => false | ||
} | ||
Comment on lines
+30
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like duplicate code, compared to |
||
|
||
def apply(dt: DataType): LiteralTypeOps = TypeOps(dt).asInstanceOf[LiteralTypeOps] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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.catalyst.types | ||
|
||
import org.apache.spark.sql.catalyst.expressions.MutableValue | ||
import org.apache.spark.sql.types.{DataType, TimeType} | ||
|
||
// Base operations over Catalyst's types. | ||
trait PhyTypeOps extends TypeOps { | ||
// Gets the underlying physical type | ||
def getPhysicalType: PhysicalDataType | ||
|
||
// Gets the Java class of the physical type | ||
def getJavaClass: Class[_] | ||
|
||
// Gets a mutable container for the physical type | ||
def getMutableValue: MutableValue | ||
} | ||
|
||
object PhyTypeOps { | ||
def supports(dt: DataType): Boolean = dt match { | ||
case _: TimeType => true | ||
case _ => false | ||
} | ||
Comment on lines
+36
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even this is somewhat of a duplicate, given that we already kind of match TimeType as part of TypeOps. Ideal scenario would be to do this logic only once, without the need to add TimeType to several matches. |
||
|
||
def apply(dt: DataType): PhyTypeOps = TypeOps(dt).asInstanceOf[PhyTypeOps] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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.catalyst.types | ||
|
||
import org.apache.spark.sql.catalyst.expressions.{Literal, MutableLong, MutableValue} | ||
import org.apache.spark.sql.types.TimeType | ||
|
||
case class TimeTypeOps (t: TimeType) | ||
extends TypeOps | ||
with PhyTypeOps | ||
with LiteralTypeOps { | ||
|
||
override def getPhysicalType: PhysicalDataType = PhysicalLongType | ||
override def getJavaClass: Class[_] = classOf[PhysicalLongType.InternalType] | ||
override def getMutableValue: MutableValue = new MutableLong | ||
|
||
override def getDefaultLiteral: Literal = Literal.create(0L, t) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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.catalyst.types | ||
|
||
import org.apache.spark.SparkException | ||
import org.apache.spark.sql.types.{DataType, TimeType} | ||
|
||
// Operations over a data type | ||
trait TypeOps | ||
|
||
// The factory of type operation objects. | ||
object TypeOps { | ||
def apply(dt: DataType): TypeOps = dt match { | ||
case tt: TimeType => TimeTypeOps(tt) | ||
case other => throw SparkException.internalError( | ||
s"Cannot create an operation object of the type ${other.sql}") | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, we will get an Ops object here, and we will match by it instead of
PhyTypeOps.supports
. The current implementation is just workaround to avoid passingTypeOps
instead ofDataType
.