-
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
22 changed files
with
1,192 additions
and
5 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
sql/core/src/main/java/org/apache/spark/sql/api/java/types/ArrayType.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,63 @@ | ||
/* | ||
* 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.api.java.types; | ||
|
||
/** | ||
* The data type representing Lists. | ||
* An ArrayType object comprises two fields, {@code DataType elementType} and | ||
* {@code boolean containsNull}. The field of {@code elementType} is used to specify the type of | ||
* array elements. The field of {@code containsNull} is used to specify if the array can have | ||
* any {@code null} value. | ||
*/ | ||
public class ArrayType extends DataType { | ||
private DataType elementType; | ||
private boolean containsNull; | ||
|
||
protected ArrayType(DataType elementType, boolean containsNull) { | ||
this.elementType = elementType; | ||
this.containsNull = containsNull; | ||
} | ||
|
||
public DataType getElementType() { | ||
return elementType; | ||
} | ||
|
||
public boolean isContainsNull() { | ||
return containsNull; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
ArrayType arrayType = (ArrayType) o; | ||
|
||
if (containsNull != arrayType.containsNull) return false; | ||
if (!elementType.equals(arrayType.elementType)) return false; | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = elementType.hashCode(); | ||
result = 31 * result + (containsNull ? 1 : 0); | ||
return result; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
sql/core/src/main/java/org/apache/spark/sql/api/java/types/BinaryType.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,25 @@ | ||
/* | ||
* 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.api.java.types; | ||
|
||
/** | ||
* The data type representing byte[] values. | ||
*/ | ||
public class BinaryType extends DataType { | ||
protected BinaryType() {} | ||
} |
22 changes: 22 additions & 0 deletions
22
sql/core/src/main/java/org/apache/spark/sql/api/java/types/BooleanType.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,22 @@ | ||
/* | ||
* 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.api.java.types; | ||
|
||
public class BooleanType extends DataType { | ||
protected BooleanType() {} | ||
} |
25 changes: 25 additions & 0 deletions
25
sql/core/src/main/java/org/apache/spark/sql/api/java/types/ByteType.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,25 @@ | ||
/* | ||
* 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.api.java.types; | ||
|
||
/** | ||
* The data type representing Byte values. | ||
*/ | ||
public class ByteType extends DataType { | ||
protected ByteType() {} | ||
} |
161 changes: 161 additions & 0 deletions
161
sql/core/src/main/java/org/apache/spark/sql/api/java/types/DataType.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,161 @@ | ||
/* | ||
* 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.api.java.types; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* The base type of all Spark SQL data types. | ||
*/ | ||
public abstract class DataType { | ||
|
||
/** | ||
* Gets the StringType object. | ||
*/ | ||
public static final StringType StringType = new StringType(); | ||
|
||
/** | ||
* Gets the BinaryType object. | ||
*/ | ||
public static final BinaryType BinaryType = new BinaryType(); | ||
|
||
/** | ||
* Gets the BooleanType object. | ||
*/ | ||
public static final BooleanType BooleanType = new BooleanType(); | ||
|
||
/** | ||
* Gets the TimestampType object. | ||
*/ | ||
public static final TimestampType TimestampType = new TimestampType(); | ||
|
||
/** | ||
* Gets the DecimalType object. | ||
*/ | ||
public static final DecimalType DecimalType = new DecimalType(); | ||
|
||
/** | ||
* Gets the DoubleType object. | ||
*/ | ||
public static final DoubleType DoubleType = new DoubleType(); | ||
|
||
/** | ||
* Gets the FloatType object. | ||
*/ | ||
public static final FloatType FloatType = new FloatType(); | ||
|
||
/** | ||
* Gets the ByteType object. | ||
*/ | ||
public static final ByteType ByteType = new ByteType(); | ||
|
||
/** | ||
* Gets the IntegerType object. | ||
*/ | ||
public static final IntegerType IntegerType = new IntegerType(); | ||
|
||
/** | ||
* Gets the LongType object. | ||
*/ | ||
public static final LongType LongType = new LongType(); | ||
|
||
/** | ||
* Gets the ShortType object. | ||
*/ | ||
public static final ShortType ShortType = new ShortType(); | ||
|
||
/** | ||
* Creates an ArrayType by specifying the data type of elements ({@code elementType}) and | ||
* whether the array contains null values ({@code containsNull}). | ||
* @param elementType | ||
* @param containsNull | ||
* @return | ||
*/ | ||
public static ArrayType createArrayType(DataType elementType, boolean containsNull) { | ||
if (elementType == null) { | ||
throw new IllegalArgumentException("elementType should not be null."); | ||
} | ||
|
||
return new ArrayType(elementType, containsNull); | ||
} | ||
|
||
/** | ||
* Creates a MapType by specifying the data type of keys ({@code keyType}) and values | ||
* ({@code keyType}). | ||
* @param keyType | ||
* @param valueType | ||
* @return | ||
*/ | ||
public static MapType createMapType(DataType keyType, DataType valueType) { | ||
if (keyType == null) { | ||
throw new IllegalArgumentException("keyType should not be null."); | ||
} | ||
if (valueType == null) { | ||
throw new IllegalArgumentException("valueType should not be null."); | ||
} | ||
|
||
return new MapType(keyType, valueType); | ||
} | ||
|
||
/** | ||
* Creates a StructField by specifying the name ({@code name}), data type ({@code dataType}) and | ||
* whether values of this field can be null values ({@code nullable}). | ||
* @param name | ||
* @param dataType | ||
* @param nullable | ||
* @return | ||
*/ | ||
public static StructField createStructField(String name, DataType dataType, boolean nullable) { | ||
if (name == null) { | ||
throw new IllegalArgumentException("name should not be null."); | ||
} | ||
if (dataType == null) { | ||
throw new IllegalArgumentException("dataType should not be null."); | ||
} | ||
|
||
return new StructField(name, dataType, nullable); | ||
} | ||
|
||
/** | ||
* Creates a StructType with the given StructFields ({@code fields}). | ||
* @param fields | ||
* @return | ||
*/ | ||
public static StructType createStructType(List<StructField> fields) { | ||
if (fields == null) { | ||
throw new IllegalArgumentException("fields should not be null."); | ||
} | ||
Set<String> distinctNames = new HashSet<String>(); | ||
for (StructField field: fields) { | ||
if (field == null) { | ||
throw new IllegalArgumentException( | ||
"fields should not contain any null."); | ||
} | ||
|
||
distinctNames.add(field.getName()); | ||
} | ||
if (distinctNames.size() != fields.size()) { | ||
throw new IllegalArgumentException( | ||
"fields should have distinct names."); | ||
} | ||
|
||
return new StructType(fields); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
sql/core/src/main/java/org/apache/spark/sql/api/java/types/DecimalType.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,25 @@ | ||
/* | ||
* 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.api.java.types; | ||
|
||
/** | ||
* The data type representing java.math.BigDecimal values. | ||
*/ | ||
public class DecimalType extends DataType { | ||
protected DecimalType() {} | ||
} |
25 changes: 25 additions & 0 deletions
25
sql/core/src/main/java/org/apache/spark/sql/api/java/types/DoubleType.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,25 @@ | ||
/* | ||
* 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.api.java.types; | ||
|
||
/** | ||
* The data type representing Double values. | ||
*/ | ||
public class DoubleType extends DataType { | ||
protected DoubleType() {} | ||
} |
25 changes: 25 additions & 0 deletions
25
sql/core/src/main/java/org/apache/spark/sql/api/java/types/FloatType.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,25 @@ | ||
/* | ||
* 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.api.java.types; | ||
|
||
/** | ||
* The data type representing Float values. | ||
*/ | ||
public class FloatType extends DataType { | ||
protected FloatType() {} | ||
} |
Oops, something went wrong.