@@ -196,6 +196,45 @@ describe('validateWithSchema', () => {
196196 } ) ;
197197 } ) ;
198198
199+ describe ( 'column validation without FROM clause' , ( ) => {
200+ it ( 'should detect unknown columns when no FROM clause is present' , ( ) => {
201+ const result = validateWithSchema ( 'SELECT scooby' , schema ) ;
202+ expect ( result . valid ) . toBe ( false ) ;
203+ const error = result . errors . find ( ( e ) => e . code === 'E201' ) ;
204+ expect ( error ) . toBeDefined ( ) ;
205+ expect ( error ?. message ) . toContain ( 'scooby' ) ;
206+ } ) ;
207+
208+ it ( 'should pass known columns even without FROM clause' , ( ) => {
209+ const result = validateWithSchema ( 'SELECT id' , schema ) ;
210+ expect ( result . valid ) . toBe ( true ) ;
211+ } ) ;
212+
213+ it ( 'should detect unknown columns with dialect specified' , ( ) => {
214+ const clickhouseSchema : Schema = {
215+ tables : [
216+ {
217+ name : 'demo_daily_orders' ,
218+ columns : [
219+ { name : 'date' , type : 'Date' } ,
220+ { name : 'category' , type : 'String' } ,
221+ { name : 'transactions' , type : 'Int64' } ,
222+ ] ,
223+ } ,
224+ ] ,
225+ } ;
226+ const result = validateWithSchema (
227+ 'SELECT scooby' ,
228+ clickhouseSchema ,
229+ 'clickhouse' ,
230+ ) ;
231+ expect ( result . valid ) . toBe ( false ) ;
232+ const error = result . errors . find ( ( e ) => e . code === 'E201' ) ;
233+ expect ( error ) . toBeDefined ( ) ;
234+ expect ( error ?. message ) . toContain ( 'scooby' ) ;
235+ } ) ;
236+ } ) ;
237+
199238 describe ( 'strict mode' , ( ) => {
200239 it ( 'should report errors in strict mode (default)' , ( ) => {
201240 const result = validateWithSchema ( 'SELECT unknown FROM users' , schema ) ;
0 commit comments