-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
8 changed files
with
188 additions
and
115 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
59 changes: 59 additions & 0 deletions
59
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/UDTRegistry.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,59 @@ | ||
/* | ||
* 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 | ||
|
||
import org.apache.spark.sql.catalyst.annotation.UserDefinedType | ||
|
||
import scala.collection.mutable | ||
|
||
import org.apache.spark.sql.catalyst.types.UserDefinedTypeType | ||
|
||
import scala.reflect.runtime.universe._ | ||
|
||
/** | ||
* Global registry for user-defined types (UDTs). | ||
*/ | ||
private[sql] object UDTRegistry { | ||
/** Map: UserType --> UserDefinedType */ | ||
val udtRegistry = new mutable.HashMap[Any, UserDefinedTypeType[_]]() | ||
|
||
/** | ||
* Register a user-defined type and its serializer, to allow automatic conversion between | ||
* RDDs of user types and SchemaRDDs. | ||
* Fails if this type has been registered already. | ||
*/ | ||
/* | ||
def registerType[UserType](implicit userType: TypeTag[UserType]): Unit = { | ||
// TODO: Check to see if type is built-in. Throw exception? | ||
val udt: UserDefinedTypeType[_] = | ||
userType.getClass.getAnnotation(classOf[UserDefinedType]).udt().newInstance() | ||
UDTRegistry.udtRegistry(userType.tpe) = udt | ||
}*/ | ||
|
||
def registerType[UserType](implicit userType: Type): Unit = { | ||
// TODO: Check to see if type is built-in. Throw exception? | ||
if (!UDTRegistry.udtRegistry.contains(userType)) { | ||
val udt: UserDefinedTypeType[_] = | ||
userType.getClass.getAnnotation(classOf[UserDefinedType]).udt().newInstance() | ||
UDTRegistry.udtRegistry(userType) = udt | ||
} | ||
// TODO: Else: Should we check (assert) that udt is the same as what is in the registry? | ||
} | ||
|
||
//def getUDT | ||
} |
32 changes: 32 additions & 0 deletions
32
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/annotation/UserDefinedType.java
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,32 @@ | ||
/* | ||
* 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.annotation; | ||
|
||
import org.apache.spark.sql.catalyst.types.UserDefinedTypeType; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* A user-defined type which can be automatically recognized by a SQLContext and registered. | ||
*/ | ||
// TODO: Should I used @Documented ? | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface UserDefinedType { | ||
Class<? extends UserDefinedTypeType<?> > udt(); | ||
} |
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
Oops, something went wrong.