Skip to content

Commit

Permalink
standardize asserts in core
Browse files Browse the repository at this point in the history
  • Loading branch information
Garg, Prateek [Engineering] authored and PrateekGarg-gs committed Jun 14, 2024
1 parent 29f2aab commit 974305d
Show file tree
Hide file tree
Showing 138 changed files with 1,702 additions and 1,439 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import meta::external::store::relational::runtime::*;
function <<test.Test>> meta::relational::tests::functions::sqlstring::databricks::testToSQLStringDatabricksSchemaNameShouldContainCatalogName():Boolean[1]
{
let s = toSQLString(|Person.all(), meta::relational::tests::simpleRelationalMappingPersonForDatabricksCatalog, meta::relational::runtime::DatabaseType.Databricks, meta::relational::extension::relationalExtensions());
assertEquals('select `root`.ID as `pk_0`, `root`.FIRSTNAME as `firstName`, `root`.LASTNAME as `lastName`, `root`.AGE as `age` from catalog.schema.personTable as `root`', $s);
assertSameSQL('select `root`.ID as `pk_0`, `root`.FIRSTNAME as `firstName`, `root`.LASTNAME as `lastName`, `root`.AGE as `age` from catalog.schema.personTable as `root`', $s);
}

function <<test.Test>> meta::relational::tests::functions::sqlstring::databricks::testToSQLStringDatabricksSchemaNameShouldNotContainCatalogName():Boolean[1]
{
let s = toSQLString(|Person.all(), meta::relational::tests::simpleRelationalMappingPersonForDatabricks, meta::relational::runtime::DatabaseType.Databricks, meta::relational::extension::relationalExtensions());
assertEquals('select `root`.ID as `pk_0`, `root`.FIRSTNAME as `firstName`, `root`.LASTNAME as `lastName`, `root`.AGE as `age` from schema.personTable as `root`', $s);
assertSameSQL('select `root`.ID as `pk_0`, `root`.FIRSTNAME as `firstName`, `root`.LASTNAME as `lastName`, `root`.AGE as `age` from schema.personTable as `root`', $s);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ import meta::core::runtime::*;
import meta::relational::runtime::*;
import meta::external::store::relational::runtime::*;
import meta::relational::runtime::authentication::*;
import meta::relational::functions::asserts::*;

function <<test.Test>> meta::relational::tests::mapping::sqlFunction::hive::testTriminNotSybaseASE():Boolean[1]{

let sHive = toSQLString(|SqlFunctionDemo.all()->project([s | $s.trimResult], ['trim']),
testMapping,
meta::relational::runtime::DatabaseType.Hive, meta::relational::extension::relationalExtensions());

assertEquals('select trim("root".string2) as "trim" from dataTable as "root"',$sHive);
assertSameSQL('select trim("root".string2) as "trim" from dataTable as "root"',$sHive);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,36 @@

import meta::relational::tests::model::simple::*;
import meta::relational::functions::sqlstring::*;
import meta::relational::functions::asserts::*;

function <<test.Test>> meta::relational::memsql::tests::query::take::testSlice_MemSQL():Boolean[1]
{
let s2 = toSQLString(|Person.all()->slice(3, 5);, meta::relational::tests::simpleRelationalMapping, meta::relational::runtime::DatabaseType.MemSQL, meta::relational::extension::relationalExtensions());
assertEquals('select `root`.ID as `pk_0`, `root`.FIRSTNAME as `firstName`, `root`.AGE as `age`, `root`.LASTNAME as `lastName` from personTable as `root` limit 3,2', $s2);
assertSameSQL('select `root`.ID as `pk_0`, `root`.FIRSTNAME as `firstName`, `root`.AGE as `age`, `root`.LASTNAME as `lastName` from personTable as `root` limit 3,2', $s2);
}

function <<test.Test>> meta::relational::memsql::tests::query::take::testLimit_MemSQL():Boolean[1]
{
let s3 = toSQLString(|Person.all()->limit(1);,meta::relational::tests::simpleRelationalMapping, meta::relational::runtime::DatabaseType.MemSQL, meta::relational::extension::relationalExtensions());
assertEquals('select `root`.ID as `pk_0`, `root`.FIRSTNAME as `firstName`, `root`.AGE as `age`, `root`.LASTNAME as `lastName` from personTable as `root` limit 1', $s3);
assertSameSQL('select `root`.ID as `pk_0`, `root`.FIRSTNAME as `firstName`, `root`.AGE as `age`, `root`.LASTNAME as `lastName` from personTable as `root` limit 1', $s3);
}

function <<test.Test>> meta::relational::memsql::tests::query::take::testTake_MemSQL():Boolean[1]
{
let s3 = toSQLString(|Person.all()->take(10);, meta::relational::tests::simpleRelationalMapping, meta::relational::runtime::DatabaseType.MemSQL, meta::relational::extension::relationalExtensions());
assertEquals('select `root`.ID as `pk_0`, `root`.FIRSTNAME as `firstName`, `root`.AGE as `age`, `root`.LASTNAME as `lastName` from personTable as `root` limit 10', $s3);
assertSameSQL('select `root`.ID as `pk_0`, `root`.FIRSTNAME as `firstName`, `root`.AGE as `age`, `root`.LASTNAME as `lastName` from personTable as `root` limit 10', $s3);
}

function <<test.Test>> meta::relational::memsql::tests::query::take::testDrop_MemSQL():Boolean[1]
{
let s3 = toSQLString(|Person.all()->drop(10);, meta::relational::tests::simpleRelationalMapping, meta::relational::runtime::DatabaseType.MemSQL, meta::relational::extension::relationalExtensions());
assertEquals('select `limitoffset_via_window_subquery`.`pk_0` as `pk_0`, `limitoffset_via_window_subquery`.`firstName` as `firstName`, `limitoffset_via_window_subquery`.`age` as `age`, `limitoffset_via_window_subquery`.`lastName` as `lastName` from (select `root`.ID as `pk_0`, `root`.FIRSTNAME as `firstName`, `root`.AGE as `age`, `root`.LASTNAME as `lastName`, row_number() OVER (Order By `root`.ID) as `row_number` from personTable as `root`) as `limitoffset_via_window_subquery` where `limitoffset_via_window_subquery`.row_number > 10', $s3);
assertSameSQL('select `limitoffset_via_window_subquery`.`pk_0` as `pk_0`, `limitoffset_via_window_subquery`.`firstName` as `firstName`, `limitoffset_via_window_subquery`.`age` as `age`, `limitoffset_via_window_subquery`.`lastName` as `lastName` from (select `root`.ID as `pk_0`, `root`.FIRSTNAME as `firstName`, `root`.AGE as `age`, `root`.LASTNAME as `lastName`, row_number() OVER (Order By `root`.ID) as `row_number` from personTable as `root`) as `limitoffset_via_window_subquery` where `limitoffset_via_window_subquery`.row_number > 10', $s3);
let s4 = toSQLString(|Person.all()->project([col(p|$p.firstName, 'firstName'), col(p|$p.lastName, 'lastName')])->drop(10);, meta::relational::tests::simpleRelationalMapping, meta::relational::runtime::DatabaseType.MemSQL, meta::relational::extension::relationalExtensions());
assertEquals('select `limitoffset_via_window_subquery`.`firstName` as `firstName`, `limitoffset_via_window_subquery`.`lastName` as `lastName` from (select `root`.FIRSTNAME as `firstName`, `root`.LASTNAME as `lastName`, row_number() OVER (Order By `root`.FIRSTNAME) as `row_number` from personTable as `root`) as `limitoffset_via_window_subquery` where `limitoffset_via_window_subquery`.row_number > 10', $s4);
assertSameSQL('select `limitoffset_via_window_subquery`.`firstName` as `firstName`, `limitoffset_via_window_subquery`.`lastName` as `lastName` from (select `root`.FIRSTNAME as `firstName`, `root`.LASTNAME as `lastName`, row_number() OVER (Order By `root`.FIRSTNAME) as `row_number` from personTable as `root`) as `limitoffset_via_window_subquery` where `limitoffset_via_window_subquery`.row_number > 10', $s4);
}

function <<test.Test>> meta::relational::memsql::tests::query::take::testDropLimit_MemSQL():Boolean[1]
{
let s = toSQLString(|Person.all()->project([col(p|$p.firstName, 'firstName'), col(p|$p.lastName, 'lastName')])->drop(10)->limit(100);, meta::relational::tests::simpleRelationalMapping, meta::relational::runtime::DatabaseType.MemSQL, meta::relational::extension::relationalExtensions());
assertEquals('select `firstName` as `firstName`, `lastName` as `lastName` from (select `limitoffset_via_window_subquery`.`firstName` as `firstName`, `limitoffset_via_window_subquery`.`lastName` as `lastName` from (select `root`.FIRSTNAME as `firstName`, `root`.LASTNAME as `lastName`, row_number() OVER (Order By `root`.FIRSTNAME) as `row_number` from personTable as `root`) as `limitoffset_via_window_subquery` where `limitoffset_via_window_subquery`.row_number > 10) as `subselect` limit 100', $s);
assertSameSQL('select `firstName` as `firstName`, `lastName` as `lastName` from (select `limitoffset_via_window_subquery`.`firstName` as `firstName`, `limitoffset_via_window_subquery`.`lastName` as `lastName` from (select `root`.FIRSTNAME as `firstName`, `root`.LASTNAME as `lastName`, row_number() OVER (Order By `root`.FIRSTNAME) as `row_number` from personTable as `root`) as `limitoffset_via_window_subquery` where `limitoffset_via_window_subquery`.row_number > 10) as `subselect` limit 100', $s);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import meta::relational::functions::sqlstring::*;
import meta::relational::functions::asserts::*;

Class meta::relational::memsql::tests::db::A
{
Expand All @@ -29,7 +30,7 @@ function <<test.Test>> meta::relational::memsql::tests::db::testQuoteIdentifiers
true,
meta::relational::extension::relationalExtensions());

assertEquals('select `root`.`window` as `WINDOW` from `test table` as `root`', $result);
assertSameSQL('select `root`.`window` as `WINDOW` from `test table` as `root`', $result);
}

function <<test.Test>> meta::relational::memsql::tests::db::testReservedKeywords() : Boolean[1]
Expand All @@ -40,7 +41,7 @@ function <<test.Test>> meta::relational::memsql::tests::db::testReservedKeywords
meta::relational::runtime::DatabaseType.MemSQL,
meta::relational::extension::relationalExtensions());

assertEquals('select `root`.`window` as `WINDOW` from `test table` as `root`', $result);
assertSameSQL('select `root`.`window` as `WINDOW` from `test table` as `root`', $result);
}

function <<test.Test>> meta::relational::memsql::tests::db::testWeekOfYear() : Boolean[1]
Expand All @@ -51,7 +52,7 @@ function <<test.Test>> meta::relational::memsql::tests::db::testWeekOfYear() : B
meta::relational::runtime::DatabaseType.MemSQL,
meta::relational::extension::relationalExtensions());

assertEquals('select weekofyear(date(`root`.dateTime)) as `week` from dataTable as `root`', $result);
assertSameSQL('select weekofyear(date(`root`.dateTime)) as `week` from dataTable as `root`', $result);
}

function <<test.Test>> meta::relational::memsql::tests::db::testDayOfYear() : Boolean[1]
Expand All @@ -62,7 +63,7 @@ function <<test.Test>> meta::relational::memsql::tests::db::testDayOfYear() : Bo
meta::relational::runtime::DatabaseType.MemSQL,
meta::relational::extension::relationalExtensions());

assertEquals('select dayofyear(date(`root`.dateTime)) as `doy` from dataTable as `root`', $result);
assertSameSQL('select dayofyear(date(`root`.dateTime)) as `doy` from dataTable as `root`', $result);
}

###Relational
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import meta::relational::tests::model::simple::*;
import meta::external::store::relational::runtime::*;
import meta::relational::runtime::*;
import meta::relational::functions::sqlstring::*;
import meta::relational::functions::asserts::*;

function <<test.Test>> meta::relational::memsql::tests::tds::sort::testSortQuotes_MemSQL():Boolean[1]
{
let query = toSQLString(|Person.all()->project([#/Person/firstName!name#, #/Person/address/name!address#])->sort(desc('address'))->sort('name');, simpleRelationalMapping, DatabaseType.MemSQL, meta::relational::extension::relationalExtensions());
assertEquals('select `root`.FIRSTNAME as `name`, `addressTable_d#3_1_d#3_m2`.NAME as `address` from personTable as `root` left outer join addressTable as `addressTable_d#3_1_d#3_m2` on (`addressTable_d#3_1_d#3_m2`.ID = `root`.ADDRESSID) order by `name`,`address` desc', $query);
assertSameSQL('select `root`.FIRSTNAME as `name`, `addressTable_d#3_1_d#3_m2`.NAME as `address` from personTable as `root` left outer join addressTable as `addressTable_d#3_1_d#3_m2` on (`addressTable_d#3_1_d#3_m2`.ID = `root`.ADDRESSID) order by `name`,`address` desc', $query);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import meta::relational::runtime::*;
import meta::pure::functions::math::olap::*;
import meta::relational::tests::model::simple::*;
import meta::relational::functions::sqlstring::*;
import meta::relational::functions::asserts::*;

function <<test.Test>> meta::relational::memsql::tests::tds::tdsWindow::testSingleWindowWithSortingRank_MemSQL():Boolean[1]
{
Expand All @@ -27,5 +28,5 @@ function <<test.Test>> meta::relational::memsql::tests::tds::tdsWindow::testSing
->sort('rank')
};
let result = toSQLString($func, simpleRelationalMapping, DatabaseType.MemSQL, meta::relational::extension::relationalExtensions(),debug());
assertEquals('select `firstName` as `firstName`, `lastName` as `lastName`, `age` as `age`, `rank` as `rank` from (select `root`.FIRSTNAME as `firstName`, `root`.LASTNAME as `lastName`, `root`.AGE as `age`, dense_rank() OVER (Partition By `root`.FIRSTNAME Order By `root`.LASTNAME DESC) as `rank` from personTable as `root`) as `subselect` order by `rank`', $result);
assertSameSQL('select `firstName` as `firstName`, `lastName` as `lastName`, `age` as `age`, `rank` as `rank` from (select `root`.FIRSTNAME as `firstName`, `root`.LASTNAME as `lastName`, `root`.AGE as `age`, dense_rank() OVER (Partition By `root`.FIRSTNAME Order By `root`.LASTNAME DESC) as `rank` from personTable as `root`) as `subselect` order by `rank`', $result);
}
Loading

0 comments on commit 974305d

Please sign in to comment.