JuliaDB column names

juliadb
#1

I have pulled data from an Oracle database using JDBC and collected the results using the following code:

oracle_cursor = JDBC.cursor(oracle_connection)
execute!(oracle_cursor, "SQL STATEMENT")

column_names = map(x -> Symbol(x), JDBC.colnames(JDBC.Source(oracle_cursor))) 
advstand_data = JuliaDB.table(collect(JDBC.rows(oracle_cursor))) 

The resulting JuliaDB is Tuple{String,Union{Missing, String},String,String,Float32} which is not a Named Tuple and has colnames(advstand_data) = (1, 2, 3, 4, 5). I am trying to use JuliaDB.renamecol to change the column names.

The following code does not change the column name:
advstand_data = renamecol(advstand_data, colnames(advstand_data)[1], :COLUMN_1)

The following code has the following error:

ERROR: 1 not found. Cannot rename it.
Stacktrace:
 [1] rename!(::ColDict{IndexedTable{StructArray{Tuple{String,Union{Missing, String},String,String,Float32},1,NamedTuple{(:x1, :x2, :x3, :x4, :x5),Tuple{WeakRefStrings.StringArray{String,1},WeakRefStrings.StringArray{Union{Missing, String},1},WeakRefStrings.StringArray{String,1},WeakRefStrings.StringArray{String,1},Array{Float32,1}}}}}}, ::Symbol, ::Symbol) at C:\Users\jmbyars\.julia\packages\IndexedTables\DgX0A\src\columns.jl:471
 [2] renamecol(::IndexedTable{StructArray{Tuple{String,Union{Missing, String},String,String,Float32},1,NamedTuple{(:x1, :x2, :x3, :x4, :x5),Tuple{WeakRefStrings.StringArray{String,1},WeakRefStrings.StringArray{Union{Missing, String},1},WeakRefStrings.StringArray{String,1},WeakRefStrings.StringArray{String,1},Array{Float32,1}}}}}, ::Symbol, ::Vararg{Symbol,N} where N) at C:\Users\jmbyars\.julia\packages\IndexedTables\DgX0A\src\columns.jl:505
 [3] top-level scope at none:0

Is there any recommendations on fixing the column names?

#2

cc: @joshday @piever

#3

You can use columns to extract the tuple of vectors and create a new table (without copying the data):

using JuliaDB

t = table(1:10,rand(10))

table(columns(t)..., names=(:x, :y), copy=false)
#4

Thanks for the reply. I’ll try it out tomorrow to see if it fixes my problem. I am relatively new to Julia as I am trying to redo the daily tasks I do in R in Julia. I have seen the ... in several programming examples. What does it mean in Julia?

#5

... is the splat operator. See https://docs.julialang.org/en/v1/manual/faq/index.html#What-does-the-…-operator-do?-1

Cheers,
Kevin