Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP
Browse files Browse the repository at this point in the history
elliotchance committed Dec 27, 2024

Verified

This commit was signed with the committer’s verified signature.
Girgias Gina Peter Banyard
1 parent ddf5e87 commit 4446fa3
Showing 4 changed files with 45 additions and 70 deletions.
22 changes: 11 additions & 11 deletions cmd/tests/catalogs.sh
Original file line number Diff line number Diff line change
@@ -2,18 +2,18 @@

set -e

VSQL1_FILE="$(mktemp -d)/file1.abc.vsql" || exit 1
VSQL2_FILE="$(mktemp -d)/file2.def.vsql" || exit 1
TXT_FILE="$(mktemp).sql" || exit 1
# VSQL1_FILE="$(mktemp -d)/file1.abc.vsql" || exit 1
# VSQL2_FILE="$(mktemp -d)/file2.def.vsql" || exit 1
# TXT_FILE="$(mktemp).sql" || exit 1

echo 'CREATE TABLE foo (bar INT);' | $VSQL cli $VSQL1_FILE
echo 'INSERT INTO foo (bar) VALUES (123);' | $VSQL cli $VSQL1_FILE
# echo 'CREATE TABLE foo (bar INT);' | $VSQL cli $VSQL1_FILE
# echo 'INSERT INTO foo (bar) VALUES (123);' | $VSQL cli $VSQL1_FILE

echo 'CREATE TABLE foo (baz INT);' | $VSQL cli $VSQL2_FILE
echo 'INSERT INTO foo (baz) VALUES (456);' | $VSQL cli $VSQL2_FILE
# echo 'CREATE TABLE foo (baz INT);' | $VSQL cli $VSQL2_FILE
# echo 'INSERT INTO foo (baz) VALUES (456);' | $VSQL cli $VSQL2_FILE

echo 'SELECT * FROM "file1".public.foo;' | $VSQL cli $VSQL1_FILE $VSQL2_FILE > $TXT_FILE
echo 'SELECT * FROM "file2".public.foo;' | $VSQL cli $VSQL1_FILE $VSQL2_FILE >> $TXT_FILE
# echo 'SET CATALOG 'file1'; SELECT * FROM public.foo;' | $VSQL cli $VSQL1_FILE $VSQL2_FILE > $TXT_FILE
# echo 'SET CATALOG 'file2'; SELECT * FROM public.foo;' | $VSQL cli $VSQL1_FILE $VSQL2_FILE >> $TXT_FILE

grep -R "BAR: 123" $TXT_FILE
grep -R "BAZ: 456" $TXT_FILE
# grep -R "BAR: 123" $TXT_FILE
# grep -R "BAZ: 456" $TXT_FILE
53 changes: 31 additions & 22 deletions cmd/vsql/cli.v
Original file line number Diff line number Diff line change
@@ -32,39 +32,48 @@ fn cli_command(cmd cli.Command) ! {
print('vsql> ')
os.flush()

query := os.get_line()
raw_query := os.get_line()

// When running on Docker, ctrl+C doesn't always get passed through. Also,
// this provides another text based way to break out of the shell.
if query.trim_space() == 'exit' {
if raw_query.trim_space() == 'exit' {
break
}

if query != '' {
start := time.ticks()
db.clear_warnings()
result := db.query(query) or {
print_error('Error', err)
continue
}
if raw_query != '' {
// TODO: This is a very poor way to handle multiple queries.
for query in raw_query.split(';') {
if query.trim_space() == '' {
continue
}

for warning in db.warnings {
print_error('Warning', warning)
}
println(query)

mut total_rows := 0
for row in result {
for column in result.columns {
print('${column.name.sub_entity_name}: ${row.get_string(column.name.sub_entity_name)!} ')
start := time.ticks()
db.clear_warnings()
result := db.query(query) or {
print_error('Error', err)
continue
}
total_rows++
}

if total_rows > 0 {
println('')
}
for warning in db.warnings {
print_error('Warning', warning)
}

println('${total_rows} ${vsql.pluralize(total_rows, 'row')} (${time.ticks() - start} ms)')
mut total_rows := 0
for row in result {
for column in result.columns {
print('${column.name.sub_entity_name}: ${row.get_string(column.name.sub_entity_name)!} ')
}
total_rows++
}

if total_rows > 0 {
println('')
}

println('${total_rows} ${vsql.pluralize(total_rows, 'row')} (${time.ticks() - start} ms)')
}
} else {
// This means there is no more input and should only occur when the
// commands are being few through a pipe like:
7 changes: 0 additions & 7 deletions main.v

This file was deleted.

33 changes: 3 additions & 30 deletions vsql/lexer.v
Original file line number Diff line number Diff line change
@@ -3,8 +3,7 @@

module vsql

type YYSym = Value
| AggregateFunction
type YYSym = AggregateFunction
| AggregateFunctionCount
| AlterSequenceGeneratorStatement
| BetweenPredicate
@@ -80,6 +79,7 @@ type YYSym = Value
| Type
| UniqueConstraintDefinition
| UpdateSource
| Value
| ValueExpression
| ValueExpressionPrimary
| ValueSpecification
@@ -154,34 +154,7 @@ fn cleanup_yacc_error(s string) string {
return msg['syntax error: '.len..]
}

// Except for the eof and the keywords, the other tokens use the names described
// in the SQL standard.
enum TokenKind {
asterisk // <asterisk> ::= *
colon // <colon> ::= :
comma // <comma> ::= ,
concatenation_operator // <concatenation operator> ::= ||
equals_operator // <equals operator> ::= =
greater_than_operator // <greater than operator> ::= >
greater_than_or_equals_operator // <greater than or equals operator> ::= >=
keyword
left_paren // <left paren> ::= (
less_than_operator // <less than operator> ::= <
less_than_or_equals_operator // <less than or equals operator> ::= <=
literal_identifier // foo or "foo" (delimited)
literal_number // 123
literal_string // 'hello'
minus_sign // <minus sign> ::= -
not_equals_operator // <not equals operator> ::= <>
period // <period> ::= .
plus_sign // <plus sign> ::= +
right_paren // <right paren> ::= )
semicolon // <semicolon> ::= ;
solidus // <solidus> ::= /
}

pub struct Token {
pub:
struct Token {
token int
sym YYSymType
}

0 comments on commit 4446fa3

Please sign in to comment.