-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduckdb-FYDZESLN.js
More file actions
2 lines (2 loc) · 5.99 KB
/
Copy pathduckdb-FYDZESLN.js
File metadata and controls
2 lines (2 loc) · 5.99 KB
1
2
import"/chunk-YJSVEN5S.js";var h=["sum","count","any_value","arbitrary","array_agg","avg","bit_and","bit_or","bit_xor","bitstring_agg","bool_and","bool_or","countif","favg","fsum","geomean","kahan_sum","last","max","min","product","string_agg","sumkahan"],c=["count","any_value","arbitrary","first","countif","last","string_agg"],n=["rows","range","cumulative"],b=[{name:"sum",frames:n,result_type:"float"},{name:"avg",frames:n,result_type:"float"},{name:"count",frames:n,result_type:"float"},{name:"min",frames:n},{name:"max",frames:n},{name:"product",frames:n,result_type:"float"},{name:"median",frames:n,result_type:"float"},{name:"stddev_samp",frames:n,result_type:"float"},{name:"stddev_pop",frames:n,result_type:"float"},{name:"var_samp",frames:n,result_type:"float"},{name:"var_pop",frames:n,result_type:"float"},{name:"first_value",frames:n},{name:"last_value",frames:n},{name:"nth_value",frames:n,offset:!0},{name:"lag",offset:!0},{name:"lead",offset:!0},{name:"row_number",result_type:"float"},{name:"rank",result_type:"float"},{name:"dense_rank",result_type:"float"},{name:"percent_rank",result_type:"float"},{name:"cume_dist",result_type:"float"},{name:"ntile",offset:!0,result_type:"float"},{name:"diff",offset:!0,result_type:"float"},{name:"rate",frames:["range"],result_type:"float"}],_=[{name:"count",frames:n,result_type:"float"},{name:"min",frames:n},{name:"max",frames:n},{name:"first_value",frames:n},{name:"last_value",frames:n},{name:"nth_value",frames:n,offset:!0},{name:"lag",offset:!0},{name:"lead",offset:!0},{name:"row_number",result_type:"float"},{name:"rank",result_type:"float"},{name:"dense_rank",result_type:"float"},{name:"percent_rank",result_type:"float"},{name:"cume_dist",result_type:"float"},{name:"ntile",offset:!0,result_type:"float"}],m=["==","!=","IS DISTINCT FROM","IS NOT DISTINCT FROM",">=","<=",">","<","is null","is not null"],y=[...m,"begins with","not begins with","contains","not contains","ends with","not ends with","matches","not matches","in","not in","LIKE","NOT LIKE","ILIKE","NOT ILIKE"];function d(e){return e=e.toLowerCase(),e.startsWith("bool")?"boolean":["tinyint","smallint","integer","utinyint","usmallint"].includes(e)||["int8","int16","int32","uint8","uint16"].includes(e)?"integer":["bigint","hugeint","uhugeint","uinteger","ubigint"].includes(e)||["float","real","double","varint"].includes(e)||["int64","uint32","uint64","float32","float64"].includes(e)||e.startsWith("decimal")||e.startsWith("numeric")?"float":e.startsWith("date")?"date":e.startsWith("time")?"datetime":(e.startsWith("varchar")||e==="utf8"||e.startsWith("enum")||["json","uuid","blob","bit","interval"].includes(e)||e.startsWith("struct")||e.startsWith("map")||e.startsWith("union")||e.endsWith("[]")||console.warn(`Unknown type '${e}'`),"string")}async function u(e,t,a={}){t=t.replace(/\s+/g," ").trim();try{let s=await e.query(t);return a.columns?{rows:s.toArray(),columns:s.schema.fields.map(r=>r.name),dtypes:s.schema.fields.map(r=>r.type.toString())}:s.toArray()}catch(s){throw console.error("Query error:",s),console.error("Query:",t),s}}var g=class{db;sqlBuilder;constructor(e,t){if(!t&&customElements){let a=customElements.get("perspective-viewer");if(a)t=a.__wasm_module__;else throw new Error("Missing perspective-client.wasm")}this.db=e,this.sqlBuilder=new t.GenericSQLVirtualServerModel({column_separator:"|",like_escape_clause:"\\",regex_fn:"regexp_matches"})}getFeatures(){return{group_by:!0,split_by:!0,sort:!0,expressions:!0,window_aggregates:{integer:b,float:b,string:_,date:_,datetime:_,boolean:_},group_rollup_mode:["rollup","flat","total"],split_rollup_mode:["flat","rollup"],filter_ops:{integer:m,float:m,string:y,boolean:m,date:m,datetime:m},aggregates:{integer:h,float:h,string:c,boolean:c,date:c,datetime:c}}}async getHostedTables(){let e=this.sqlBuilder.getHostedTables();return(await u(this.db,e)).map(t=>{let a=t.toJSON();return`${a.database||"memory"}.${a.name}`})}async tableSchema(e,t){let a=this.sqlBuilder.tableSchema(e),s=await u(this.db,a),r={};for(let i of s){let l=i.toJSON(),o=l.column_name;o.startsWith("__")||(r[o]=d(l.column_type))}return r}async viewColumnSize(e,t){let a=this.sqlBuilder.viewColumnSize(e),s=await u(this.db,a),r=Number(Object.values(s[0].toJSON())[0]),i=t.group_by?.length||0,l=t.group_rollup_mode==="flat";return r-(i===0?0:l?i:i+1)}async tableSize(e){let t=this.sqlBuilder.tableSize(e),a=await u(this.db,t);return Number(a[0].toJSON()["count_star()"])}async tableMakeView(e,t,a){let s=Object.keys(a.windows??{}).length?await this.tableSchema(e):void 0,r=this.sqlBuilder.tableMakeView(e,t,a,s);await u(this.db,r)}async tableDescribe(e,t){let a={},s=this.sqlBuilder.expressionsDescribe(e,t);if(s!==void 0)try{a=await this.describeQuery(s)}catch(o){return await this.attributeExpressionErrors(e,t,o)}let r=Object.keys(t.windows??{}).length?await this.tableSchema(e):void 0,i=this.sqlBuilder.tableDescribe(e,t,r),l={};if(i!==void 0)try{l=await this.describeQuery(i)}catch(o){return{config_error:p(o)}}return{expression_schema:a,view_schema:l}}async describeQuery(e){let t=await u(this.db,e),a={};for(let s of t){let r=s.toJSON();r.column_name.startsWith("__")||(a[r.column_name]=d(r.column_type))}return a}async attributeExpressionErrors(e,t,a){let s={},r={};for(let[i,l]of Object.entries(t.expressions)){let o=this.sqlBuilder.expressionDescribe(e,l);try{let f=await u(this.db,o);s[i]=d(f[0].toJSON().column_type)}catch(f){r[i]={error_message:p(f),line:0,column:0}}}return Object.keys(r).length===0?{config_error:p(a)}:{expression_schema:s,expression_errors:r}}async viewDelete(e){let t=this.sqlBuilder.viewDelete(e);await u(this.db,t)}async viewGetMinMax(e,t,a){let s=this.sqlBuilder.viewGetMinMax(e,t,a),r=(await u(this.db,s))[0].toJSON(),[i,l]=Object.values(r);return typeof i=="bigint"&&(i=Number(i)),typeof l=="bigint"&&(l=Number(l)),{min:i??null,max:l??null}}async viewGetData(e,t,a,s,r){let i=this.sqlBuilder.viewGetData(e,t,s,a),l=await this.db.useUnsafe((o,f)=>o.runQuery(f,i));r.fromArrowIpc(l)}};function p(e){return e instanceof Error?e.message:String(e)}export{g as DuckDBHandler};
//# sourceMappingURL=/duckdb-FYDZESLN.js.map