How Jetelina determine CSV data into RDBMS

Jetelina creates a table automatically in RDBMS and NoSQL Databases by just uploading a csv file.
Well, this blog explains how determine the data type in RDBMS.
It is very simple logic. Julia has ‘eltype()’ to determine a data type. Using this function, each csv data are determined what it is.

if you could not agree with below, you can contribute to us because Jetelina is OSS. :)

#
# quoted: PgDataController.jl
#
# 1.read csv file to DataFrame
df = DataFrame(CSV.File(csvfilename))
# 2.evaluate each data with eltype()
column_type = eltype.(eachcol(df))
# 3.call getDataType()
column_type_string[i] = PgDataTypeLIst.getDataType(string(column_type[i]))

#
# quoted: PgDataTypeList.jl
#
function getDataType(c_type::String)
	ret::String = ""

	if startswith(c_type, "Int")
		ret = "integer"
	elseif startswith(c_type, "Float")
		ret = "double precision"
	elseif startswith(c_type, "InlineStrings.String")
		ret = "varchar"
	elseif startswith(c_type, "String")
		ret = "varchar"
	elseif startswith(c_type, "Dates")
		ret = "Date"
	end

	return ret
end

You can see ‘String’ data in the csv file are determined to be ‘varchar’ type. Jetelina does not adopt ‘characters length’ for them, e.g varchar(32), in PostgreSQL, but it is ‘text’ in MySQL. Because MySQL prohibits non length varchar type.
In fact, there are more steps before calling getDataType(), though the flow is like that.
Hope you make sense about the Jetelina’s way, and enjoy Julia.

Categories: