### Install and Load Plugin Source: https://docs.dolphindb.com/en/Functions/l/listPluginsByCluster.html Before listing plugins, this example shows how to install and load a plugin named 'mysql'. This is a prerequisite for using listPluginsByCluster. ```javascript // MoMSender cluster: installPlugin("mysql") loadPlugin("mysql") ``` -------------------------------- ### Get Tables from a Database Handle Source: https://docs.dolphindb.com/en/Functions/g/getTables.html This example demonstrates how to create a partitioned table and then use getTables to retrieve its name from the database handle. It requires prior setup of a database and tables. ```python n=1000000 ID=rand(10, n) dates=2017.08.07..2017.08.11 date=rand(dates, n) x=rand(10.0, n) y=rand(10, n) t1=table(ID, date, x) t2=table(ID, date, y) db = database("dfs://valueDB", VALUE, 2017.08.07..2017.08.11) pt1 = db.createPartitionedTable(t1, `pt1, `date) pt1.append!(t1) pt2 = db.createPartitionedTable(t2, `pt2, `date) pt2.append!(t2); getTables(db); // output: ["pt1","pt2"] ``` -------------------------------- ### Start Promtail Service Source: https://docs.dolphindb.com/en/Tutorials/best_practices_for_log_monitoring.html Execute this command in the Promtail installation directory to start the Promtail service in the background, using a specified configuration file and redirecting output. ```bash nohup ./promtail-linux-amd64 -config.file=./promtail.yaml >./server.log 2>&1 & ``` -------------------------------- ### Get Chunk Paths for Data Sources Source: https://docs.dolphindb.com/en/Functions/g/getChunkPath.html This example demonstrates how to create a partitioned table, define data sources using a SQL query, and then retrieve the chunk paths for those data sources using getChunkPath. It includes setup for a database and table, followed by the core function call. ```python if(existsDatabase("dfs://valuedb")){ dropDatabase("dfs://valuedb") } db=database("dfs://valuedb", VALUE, 1..10) n=1000000 t=table(rand(1..10, n) as id, rand(100.0, n) as val) pt=db.createPartitionedTable(t, `pt, `id).append!(t); ds=sqlDS(, dateColumn=`date, timeColumn=`time) ds.size(); // output: 3 ``` -------------------------------- ### Prevailing Window Join Example Setup Source: https://docs.dolphindb.com/en/Programming/SQLStatements/TableJoiners/windowjoin.html Deletes rows from t2 within a specific time range (09:56:04 to 09:56:06) to prepare for a prevailing window join example. This modifies the t2 table for subsequent operations. ```sql delete from t2 where 09:56:04<=time<=09:56:06; t2; ``` -------------------------------- ### Restore a Table using restoreTable Source: https://docs.dolphindb.com/en/Functions/r/restoreTable.html This example demonstrates how to create a partitioned table, back it up using backupDB, and then restore it using restoreTable. It shows the basic usage of restoring a table to its original location. ```python dbName = "dfs://compoDB2" n=1000 ID=rand("a"+string(1..10), n) dates=2017.08.07..2017.08.11 date=rand(dates, n) x=rand(10, n) t=table(ID, date, x) db1 = database(, VALUE, 2017.08.07..2017.08.11) db2 = database(, HASH,[INT, 20]) if(existsDatabase(dbName)){ dropDatabase(dbName) } db = database(dbName, COMPO,[ db1,db2]) //create 2 tables pt1 = db.createPartitionedTable(t, `pt1, `date`x).append!(t) pt2 = db.createPartitionedTable(t, `pt2, `date`x).append!(t) backupDB(backupDir, dbName) restoreTable(backupDir,"dfs://compoDB2",`pt1) ``` -------------------------------- ### Get week number for a specific date Source: https://docs.dolphindb.com/en/Functions/w/weekOfYear.html Returns the week number for a given date. Weeks start on Sunday. ```DolphinDB weekOfYear(2012.01.07); // output: 1 ``` ```DolphinDB weekOfYear(2013.01.07); // output: 2 ``` ```DolphinDB weekOfYear(2012.07.02); // output: 27 ``` -------------------------------- ### Python Single-Record Subscription Example Source: https://docs.dolphindb.com/en/pydoc/AdvancedOperations/SubscriptionOptions/SubscriptionOptions.html Demonstrates setting up a single-record subscription. Use this when immediate processing of individual records is required. Ensure _batchSize_ is unspecified and _msgAsTable_ is False. ```python import dolphindb as ddb import numpy as np import time s = ddb.Session() s.connect("192.168.1.113", 8848, "admin", "123456") s.run(""" share streamTable(10000:0,`time`sym`price`id, [TIMESTAMP,SYMBOL,DOUBLE,INT]) as trades """) s.enableStreaming() def handler(lst): print(lst) s.subscribe("192.168.1.113", 8848, handler, "trades", "SingleMode", offset=-1) s.run("insert into trades values(take(now(), 6), take(`000905`600001`300201`000908`600002, 6), rand(1000,6)/10.0, 1..6)") time.sleep(3) s.unsubscribe("192.168.1.113", 8848, "trades", "SingleMode") ``` -------------------------------- ### Create and Display a Table Source: https://docs.dolphindb.com/en/Programming/SQLStatements/orderOfExecute.html Creates a sample table 't' with columns 'id', 'time', and 'x', and then displays its content. ```SQL t = table(1 1 1 1 1 2 2 2 2 2 as id, 09:30:00+1 3 2 5 4 5 2 4 3 1 as time, 1 2 3 4 5 6 5 4 3 2 as x); t; ``` -------------------------------- ### Get Weekday (Starts Sunday) Source: https://docs.dolphindb.com/en/Functions/w/weekday.html Returns the weekday of a date, where Sunday is 0 and Saturday is 6. This is the default behavior. ```DolphinDB weekday 2012.12.05; // output: 3 ``` -------------------------------- ### SQL NOT LIKE Operator Example Source: https://docs.dolphindb.com/en/Programming/SQLStatements/like.html Demonstrates how to use the NOT LIKE operator to select rows where the 'id' column does not start with 'a'. ```SQL select * from t where id not like "a%" ``` -------------------------------- ### Create Directories with mkdir Source: https://docs.dolphindb.com/en/Functions/m/mkdir.html Use the mkdir function to create new directories. This example demonstrates creating multiple directories sequentially. If a directory already exists, an appropriate message is outputted. ```sql mkdir("/home/test/dir1"); mkdir("/home/test/dir2"); mkdir("/home/test/dir3"); // output: The directory [/home/test/dir3] already exists. ``` -------------------------------- ### Java Example: Uploading a Table with tryUpload Source: https://docs.dolphindb.com/en/javadoc/connection/upload_objects.html Shows how to upload a table created via `run` using the `tryUpload` method and then retrieve it. This method will throw an exception if the upload lock is already in use. ```java _@Test_ **public** **void** test_tryUpload() **throws** IOException{ DBConnection dbConnection = **new** DBConnection(); dbConnection.connect("192.168.0.68", 8848); BasicTable tb = (BasicTable) dbConnection.run("table(1..100 as id,take(`aaa,100) as name)"); Map upObj = **new** HashMap<>(); upObj.put("table_uploaded",tb); dbConnection.tryUpload(upObj); Entity entity = dbConnection.run("table_uploaded"); System.out.println(entity.getString()); } ``` -------------------------------- ### Get Second of Minute from TIME Source: https://docs.dolphindb.com/en/Functions/s/secondOfMinute.html Extracts the second of the minute from a TIME value. Returns 0 for the given example. ```python secondOfMinute(12:32:00); // output: 0 ``` -------------------------------- ### Get Tables by Cluster Name and Database URL Source: https://docs.dolphindb.com/en/Functions/g/getTablesByCluster.html This example demonstrates how to use getTablesByCluster to retrieve table names from a specified cluster and database. It first sets up a database and table, then calls the function to get the table list. ```DolphinDB db = database(directory="dfs://db1", partitionType=RANGE, partitionScheme=0 5 10) timestamp = [09:34:07,09:36:42,09:36:51,09:36:59,09:32:47,09:35:26,09:34:16,09:34:26,09:38:12] sym = `C`MS`MS`MS`IBM`IBM`C`C`C price= 49.6 29.46 29.52 30.02 174.97 175.23 50.76 50.32 51.29 qty = 2200 1900 2100 3200 6800 5400 1300 2500 8800 t = table(timestamp, sym, qty, price) dt=db.createDimensionTable(t,`dt).append!(t) getTablesByCluster("MoMSender", "dfs://db1") ``` -------------------------------- ### Setting up Text Indexing and Querying with matchAll Source: https://docs.dolphindb.com/en/Functions/m/matchAll.html This example demonstrates how to create a partitioned table with a text index on the 'remark' column and then use the matchAll function to search for rows containing both 'apple' and 'orange'. ```python // Generate data for queries stringColumn = ["There are some apples and oranges.","Mike likes apples.","Alice likes oranges.","Mike gives Alice an apple.","Alice gives Mike an orange.","John likes peaches, so he does not give them to anyone.","Mike, can you give me some apples?","Alice, can you give me some oranges?","Mike traded an orange for an apple with Alice."] t = table([1,1,1,2,2,2,3,3,3] as id1, [1,2,3,1,2,3,1,2,3] as id2, stringColumn as remark) if(existsDatabase("dfs://textDB")) dropDatabase("dfs://textDB") db = database(directory="dfs://textDB", partitionType=VALUE, partitionScheme=[1,2,3], engine="PKEY") pt = createPartitionedTable(dbHandle=db, table=t, tableName="pt", partitionColumns="id1",primaryKey=`id1`id2,indexes={"remark":"textindex(parser=english, lowercase=true, stem=true)"}) pt.tableInsert(t) // Search for rows containing "apple" and "orange" select * from pt where matchAll(textCol=remark,terms="apple orange") ``` -------------------------------- ### Example of Creating, Submitting, Stopping, and Starting a Stream Graph Source: https://docs.dolphindb.com/en/Functions/s/stopStreamGraph.html This example demonstrates the lifecycle of a stream graph, including its creation, submission with checkpoint configuration, stopping, and restarting. It also shows how to check the stream graph's metadata. ```python if !existsCatalog("orca") { createCatalog("orca") } go use catalog orca def callTimes(mutable call, mutable tempTable, msg) { call += 1 price = [call] volume = [call] t = table(price, volume) tempTable.append!(t) return t } name = "UDF" g = createStreamGraph(name) ckptConfig = { "enable":true, "interval": 10000, "timeout": 36000, "maxConcurrentCheckpoints": 1 }; g.source("trade", `price`volume, [INT,INT]) .udfEngine(callTimes,["price", "volume"], [`cnt, `tmpTable], [433, table(128:0, ["price","volume"], [INT, INT])]) .setEngineName("udf") .sink("output") g.submit(ckptConfig) go getStreamGraphMeta() stopStreamGraph("UDF") startStreamGraph("UDF") ``` -------------------------------- ### Create a sample table Source: https://docs.dolphindb.com/en/Programming/SQLStatements/cgroupby.html Creates a DolphinDB table with stock symbols, timestamps, volumes, and prices for demonstration. ```DolphinDB t = table(`A`A`A`A`B`B`B`B as sym, 09:30:06 09:30:28 09:31:46 09:31:59 09:30:19 09:30:43 09:31:23 09:31:56 as time, 10 20 10 30 20 40 30 30 as volume, 10.05 10.06 10.07 10.05 20.12 20.13 20.14 20.15 as price); t; ``` -------------------------------- ### Get Message Offset Source: https://docs.dolphindb.com/en/cppdoc/BasicOperations/subscription.html Obtain the offset of a message within its table, starting from 0. This function is only effective when no filter is specified. ```cpp int getOffset(); ```