2019-04-08 20:38:26 -04:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const fs = require('fs-extra');
|
2019-06-14 10:53:19 -04:00
|
|
|
|
2019-04-08 20:38:26 -04:00
|
|
|
const readfile = '../docs/content/querying/sql.md';
|
|
|
|
const writefile = 'lib/sql-function-doc.ts';
|
|
|
|
|
2019-06-21 00:14:54 -04:00
|
|
|
const readDoc = async () => {
|
|
|
|
const data = await fs.readFile(readfile, 'utf-8');
|
|
|
|
const lines = data.split('\n');
|
|
|
|
|
|
|
|
const functionDocs = [];
|
|
|
|
const dataTypeDocs = [];
|
|
|
|
for (let line of lines) {
|
|
|
|
const functionMatch = line.match(/^\|`(.+\(.*\))`\|(.+)\|$/);
|
|
|
|
if (functionMatch) {
|
|
|
|
functionDocs.push({
|
|
|
|
syntax: functionMatch[1],
|
2019-06-26 18:50:48 -04:00
|
|
|
description: functionMatch[2],
|
|
|
|
});
|
2019-06-21 00:14:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const dataTypeMatch = line.match(/^\|([A-Z]+)\|([A-Z]+)\|(.*)\|(.*)\|$/);
|
|
|
|
if (dataTypeMatch) {
|
|
|
|
dataTypeDocs.push({
|
|
|
|
syntax: dataTypeMatch[1],
|
2019-06-26 18:50:48 -04:00
|
|
|
description: dataTypeMatch[4] || `Druid runtime type: ${dataTypeMatch[2]}`,
|
|
|
|
});
|
2019-06-21 00:14:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure there are at least 10 functions for sanity
|
|
|
|
if (functionDocs.length < 10) {
|
2019-06-26 18:50:48 -04:00
|
|
|
throw new Error(
|
|
|
|
`Did not find enough function entries did the structure of '${readfile}' change? (found ${functionDocs.length})`,
|
|
|
|
);
|
2019-06-21 00:14:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure there are at least 5 data types for sanity
|
|
|
|
if (dataTypeDocs.length < 10) {
|
2019-06-26 18:50:48 -04:00
|
|
|
throw new Error(
|
|
|
|
`Did not find enough data type entries did the structure of '${readfile}' change? (found ${dataTypeDocs.length})`,
|
|
|
|
);
|
2019-06-21 00:14:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const content = `/*
|
2019-04-08 20:38:26 -04:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2019-06-14 10:53:19 -04:00
|
|
|
*/
|
2019-04-08 20:38:26 -04:00
|
|
|
|
2019-06-14 10:53:19 -04:00
|
|
|
// This file is auto generated and should not be modified
|
2019-04-08 20:38:26 -04:00
|
|
|
|
2019-06-21 00:14:54 -04:00
|
|
|
export interface SyntaxDescription {
|
2019-06-01 13:14:13 -04:00
|
|
|
syntax: string;
|
|
|
|
description: string;
|
2019-06-14 10:53:19 -04:00
|
|
|
}
|
|
|
|
|
2019-06-21 19:52:33 -04:00
|
|
|
// prettier-ignore
|
2019-06-21 00:14:54 -04:00
|
|
|
export const SQL_FUNCTIONS: SyntaxDescription[] = ${JSON.stringify(functionDocs, null, 2)};
|
2019-04-08 20:38:26 -04:00
|
|
|
|
2019-06-21 19:52:33 -04:00
|
|
|
// prettier-ignore
|
2019-06-21 00:14:54 -04:00
|
|
|
export const SQL_DATE_TYPES: SyntaxDescription[] = ${JSON.stringify(dataTypeDocs, null, 2)};
|
|
|
|
`;
|
2019-04-08 20:38:26 -04:00
|
|
|
|
2019-06-21 00:14:54 -04:00
|
|
|
await fs.writeFile(writefile, content, 'utf-8');
|
|
|
|
};
|
2019-04-08 20:38:26 -04:00
|
|
|
|
|
|
|
readDoc();
|