Module: Upkeep::SQLGlot::Native

Extended by:
FFI::Library
Defined in:
lib/upkeep/sqlglot/native.rb

Constant Summary collapse

LIB_NAME =
"sqlglot_rust"
SOEXT =
FFI::Platform::LIBSUFFIX

Class Method Summary collapse

Class Method Details

.build_scope(statement_json) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/upkeep/sqlglot/native.rb', line 95

def build_scope(statement_json)
  read_owned(
    sqlglot_build_scope(statement_json),
    SemanticError,
    "Failed to build SQLGlot scope"
  )
end

.find_libraryObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/upkeep/sqlglot/native.rb', line 16

def find_library
  override = ENV["UPKEEP_SQLGLOT_LIB_PATH"]
  return override if override && File.file?(override)

  gem_root = File.expand_path("../../..", __dir__)
  installed = NativeLibrary.find(__dir__, extensions: [SOEXT])
  return installed if installed

  development = NativeLibrary.find(
    File.join(
      gem_root,
      "ext",
      "sqlglot_rust",
      "sql-glot-rust",
      "target",
      "release"
    ),
    extensions: [SOEXT]
  )
  development || LIB_NAME
end

.generate(statement_json, dialect) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/upkeep/sqlglot/native.rb', line 75

def generate(statement_json, dialect)
  read_owned(
    sqlglot_generate(statement_json, dialect),
    GenerateError,
    "Failed to generate SQL from AST"
  )
end

.lineage(column, statement_json, schema_json, config_json) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/upkeep/sqlglot/native.rb', line 103

def lineage(column, statement_json, schema_json, config_json)
  read_owned(
    sqlglot_lineage(column, statement_json, schema_json, config_json),
    SemanticError,
    "Failed to build SQLGlot lineage for #{column.inspect}"
  )
end

.parse(sql, dialect) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/upkeep/sqlglot/native.rb', line 59

def parse(sql, dialect)
  read_owned(
    sqlglot_parse(sql, dialect),
    ParseError,
    "Failed to parse SQL: #{sql.inspect}"
  )
end

.qualify_columns(statement_json, schema_json, dialect) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/upkeep/sqlglot/native.rb', line 87

def qualify_columns(statement_json, schema_json, dialect)
  read_owned(
    sqlglot_qualify_columns(statement_json, schema_json, dialect),
    SemanticError,
    "Failed to qualify SQLGlot columns"
  )
end

.transpile(sql, from_dialect, to_dialect) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/upkeep/sqlglot/native.rb', line 67

def transpile(sql, from_dialect, to_dialect)
  read_owned(
    sqlglot_transpile(sql, from_dialect, to_dialect),
    TranspileError,
    "Failed to transpile SQL: #{sql.inspect}"
  )
end

.versionObject



83
84
85
# File 'lib/upkeep/sqlglot/native.rb', line 83

def version
  sqlglot_version
end