По материалам:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| stock = pd.read_csv('/datasets/stock_upd.csv') | |
| stock['item_lowercase'] = stock['item'].str.lower() | |
| apple = stock[stock['item_lowercase'].str.contains('apple')]['count'].sum() | |
| samsung = stock[stock['item_lowercase'].str.contains('samsung')]['count'].sum() | |
| stock['item_lowercase'] = stock['item_lowercase'].drop_duplicates() | |
| stock = stock.dropna().reset_index(drop=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| STUFF | |
| ( | |
| ( | |
| SELECT '-> ' + physical_name AS 'data()' | |
| FROM sys.database_files dbfiles | |
| WHERE fg.data_space_id = dbfiles.data_space_id | |
| FOR XML PATH(''), TYPE | |
| ).value('.', 'VARCHAR(MAX)'), 1, 2, '' | |
| ) as files_partition_could_be_in, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: '3.1' | |
| services: | |
| database: | |
| image: "postgres" | |
| restart: "always" | |
| environment: | |
| - POSTGRES_USER=postgres | |
| - POSTGRES_PASSWORD=postgres | |
| - POSTGRES_DB=db |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def nested_loop_join(left: List[dict], right: List[dict], on: str, how: str) -> List[dict]: | |
| """ Nested loop JOIN strategy: For every row in outer, find matching one in inner | |
| If left/right JOIN and there's no match on inner, return outer. Else, skip | |
| Params: | |
| left (list<dict>) - List of dicts representing one relation | |
| right (list<dict>) - List of dicts representing the other relation | |
| on (string) - The key in the relations to JOIN on | |
| how (string) - The JOIN (left, right, inner) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Parser(self): | |
| def advance(self): | |
| """ Advance the tokens in use | |
| """ | |
| self.current_token, self.next_token = self.next_token, next(self.tokens, None) | |
| def accept(self, expected, raise_err = True): | |
| """ Helper function to check if the next token is what we expect |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| keywords = r"(SELECT|WHERE|FROM|AND|OR|NOT)" | |
| patterns = [ | |
| (keywords, lambda scanner, token: {"token_type": "keyword", "token": token}), | |
| (r"[a-zA-Z_][a-zA-Z_0-9]*", lambda s, t: {"token_type": "name", "token": t}), | |
| (r"\*", lambda s, t: {"token_type": "all_cols","token": t}), | |
| (r">=|>|<=|<|=", lambda s, t: {"token_type": "operator","token": t}), | |
| (r"[-+]?\d*\.\d+", lambda s, t: {"token_type": "float","token": t}), | |
| (r"\d+", lambda s, t: {"token_type": "integer","token": t}), |