Skip to content

Commit

Permalink
feat(aws-glue): fixes README code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
steffeng committed Apr 12, 2022
1 parent 8050cad commit 02ee2f0
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/@aws-cdk/aws-glue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ new glue.Table(this, 'MyTable', {
A Glue view describes a view that consists of an SQL statement and a column definition as used by a Table. A minimal view definition looks like this:

```ts
new glue.View(stack, "MyView", {
declare const myDatabase: glue.Database;
new glue.View(this, "MyView", {
database: myDatabase,
tableName: "my_view",
columns: [{
Expand All @@ -470,7 +471,8 @@ new glue.View(stack, "MyView", {
A view's SQL statement may refer to resources like tables which you want to replace at deploy time. Take the following view as an example:

```ts
new glue.View(stack, "MyView", {
declare const myDatabase: glue.Database;
new glue.View(this, "MyView", {
database: myDatabase,
tableName: "my_view",
columns: [{
Expand All @@ -484,7 +486,10 @@ new glue.View(stack, "MyView", {
Now imagine that the table names can't be hardcoded. You replace value in a view's SQL statement with the optional `placeHolders` property:

```ts
new glue.View(stack, "MyView", {
declare const myDatabase: glue.Database;
declare const myTable: glue.Table;
declare const myOtherTable: glue.Table;
new glue.View(this, "MyView", {
database: myDatabase,
tableName: "my_view",
columns: [{
Expand All @@ -493,8 +498,8 @@ new glue.View(stack, "MyView", {
}],
statement: "SELECT x from ${table1} UNION SELECT x from ${table2}",
placeHolders: {
table1: table1.tableName,
table2: table2.tableName
table1: myTable.tableName,
table2: myOtherTable.tableName
}
});
```
Expand All @@ -515,9 +520,10 @@ You can include the statement and replace the placeholders like this:

```ts
import * as fs from 'fs';
import * as path from 'path';

new glue.View(stack, "MyView", {
declare const myDatabase: glue.Database;
declare const myTable: glue.Table;
declare const myOtherTable: glue.Table;
new glue.View(this, "MyView", {
database: myDatabase,
tableName: "my_view",
columns: [{
Expand All @@ -528,8 +534,8 @@ new glue.View(stack, "MyView", {
.readFileSync(path.join(__dirname, 'myView.sql'))
.toString(),
placeHolders: {
table1: table1.tableName,
table2: table2.tableName,
table1: myTable.tableName,
table2: myOtherTable.tableName,
},
});
```

0 comments on commit 02ee2f0

Please sign in to comment.