blob: bbcf361a22f2ae6a6e32b9e2a7ff3be3505fa311 [file] [log] [blame]
/*
// Licensed to Julian Hyde under one or more contributor license
// agreements. See the NOTICE file distributed with this work for
// additional information regarding copyright ownership.
//
// Julian Hyde 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 net.hydromatic.optiq.impl.csv;
import net.hydromatic.optiq.impl.java.JavaTypeFactory;
import net.hydromatic.linq4j.expressions.Primitive;
import org.eigenbase.reltype.RelDataType;
import java.util.HashMap;
import java.util.Map;
/**
* Type of a field in a CSV file.
*
* <p>Usually, and unless specified explicitly in the header row, a field is
* of type {@link #STRING}. But specifying the field type in the header row
* makes it easier to write SQL.</p>
*/
enum CsvFieldType {
STRING(String.class, "string"),
BOOLEAN(Primitive.BOOLEAN),
BYTE(Primitive.BYTE),
CHAR(Primitive.CHAR),
SHORT(Primitive.SHORT),
INT(Primitive.INT),
LONG(Primitive.LONG),
FLOAT(Primitive.FLOAT),
DOUBLE(Primitive.DOUBLE),
DATE(java.sql.Date.class, "date"),
TIME(java.sql.Time.class, "time"),
TIMESTAMP(java.sql.Timestamp.class, "timestamp");
private final Class clazz;
private final String simpleName;
private static final Map<String, CsvFieldType> MAP =
new HashMap<String, CsvFieldType>();
static {
for (CsvFieldType value : values()) {
MAP.put(value.simpleName, value);
}
}
CsvFieldType(Primitive primitive) {
this(primitive.boxClass, primitive.primitiveClass.getSimpleName());
}
CsvFieldType(Class clazz, String simpleName) {
this.clazz = clazz;
this.simpleName = simpleName;
}
public RelDataType toType(JavaTypeFactory typeFactory) {
return typeFactory.createJavaType(clazz);
}
public static CsvFieldType of(String typeString) {
return MAP.get(typeString);
}
}
// End CsvFieldType.java